source: trunk/src/read_field.m @ 445

Last change on this file since 445 was 445, checked in by sommeria, 12 years ago

possibility of dealing with series of multiple images eg tiff- introduced
bugs corrected in object creation.

File size: 9.4 KB
Line 
1
2%'read_field': read input fields in different formats
3%--------------------------------------------------------------------------
4%  function [Field,ParamOut,errormsg] = read_field(ObjectName,FileType,ParamIn)
5%
6% OUTPUT:
7% Field: matlab structure representing the field
8% ParamOut: structure representing parameters:
9%        .FieldName; field name
10%        .FieldList: menu of possible fields
11%        .VelType
12%        .CivStage: stage of civx processing (=0, not Civx, =1 (civ1), =2  (fix1)....     
13%        .Npx,.Npy: for images, nbre of pixels in x and y
14% errormsg: error message, ='' by default
15%
16%INPUT
17% ObjectName: name of the input file, or movie object when the Matlab function mmreader is used
18% FileType: type of file
19%     = netcdf : netcdf file
20%     = image : usual image as recognised by Matlab
21%     = multimage: image series stored in a single file
22%     = mmreader: movie read with mmreader
23%     = video: movie read with VideoReader (recent versions of Matlab)
24%     = vol: images representing scanned volume (images concatened in the y direction)
25% ParamIn: Matlab structure of input parameters
26%     .FieldName: name (char string) of the input field (for Civx data)
27%     .VelType: char string giving the type of velocity data ('civ1', 'filter1', 'civ2'...)
28%     .ColorVar: variable used for vector color
29%     .Npx, .Npy: nbre of pixels along x and y (used for .vol input files)
30function [Field,ParamOut,errormsg] = read_field(ObjectName,FileType,ParamIn,num)
31Field=[];
32if ~exist('num','var')
33    num=1;
34end
35if ~exist('ParamIn','var')
36    ParamIn=[];
37end
38ParamOut=ParamIn;%default
39errormsg='';
40if isfield(ParamIn,'VelType')
41VelType=ParamIn.VelType;
42end
43A=[];
44%% distingush different input file types
45try
46    switch FileType
47        case {'civx','civdata','netcdf'}  %read the first nc field
48            %         ParamOut.FieldName=ParamIn.FieldName;
49            GUIName='get_field'; %default name of the GUI get_field
50            if isfield(ParamIn,'GUIName')
51                GUIName=ParamIn.GUIName;
52            end
53            CivStage=0;
54            if ~strcmp(ParamIn.FieldName,'get_field...')% if get_field is not requested, look for Civx data
55                FieldList=calc_field;%list of possible fields for Civx data
56                ParamOut.ColorVar='';%default
57                field_index=strcmp(ParamIn.FieldName,FieldList);%look for ParamIn.FieldName in the list of possible fields for Civx data
58                if isempty(find(field_index,1))% ParamIn.FieldName is not in the list, check whether Civx data exist
59                    Data=nc2struct(ObjectName,'ListGlobalAttribute','Conventions','absolut_time_T0','civ','CivStage');
60                    % case of new civdata conventions
61                    if isequal(Data.Conventions,'uvmat/civdata')
62                        ParamOut.FieldName='velocity';%Civx data found, set .FieldName='velocity' by default
63                        ParamOut.ColorVar='ima_cor';
64                        InputField=[{ParamOut.FieldName} {ParamOut.ColorVar}];
65                        [Field,ParamOut.VelType,errormsg]=read_civdata(ObjectName,InputField,ParamIn.VelType,Data.CivStage);
66                        CivStage=Field.CivStage;
67                        ParamOut.CivStage=Field.CivStage;
68                        %case of old civx conventions
69                    elseif ~isempty(Data.absolut_time_T0)&& ~isequal(Data.civ,0)
70                        ParamOut.FieldName='velocity';%Civx data found, set .FieldName='velocity' by default
71                        ParamOut.ColorVar='ima_cor';
72                        InputField=[{ParamOut.FieldName} {ParamOut.ColorVar}];
73                        [Field,ParamOut.VelType]=read_civxdata(ObjectName,InputField,ParamIn.VelType);
74                        CivStage=Field.CivStage;
75                        ParamOut.CivStage=Field.CivStage;
76                        % not cvix file, fields will be chosen through the GUI get_field
77                    else
78                        ParamOut.FieldName='get_field...';
79                        hget_field=findobj(allchild(0),'Name',GUIName);%find the get_field... GUI
80                        if ~isempty(hget_field)
81                            delete(hget_field)%delete  get_field for reinitialisation
82                        end
83                    end
84                else
85                    InputField={ParamOut.FieldName};
86                    if isfield(ParamIn,'ColorVar')
87                        ParamOut.ColorVar=ParamIn.ColorVar;
88                        InputField=[InputField {ParamOut.ColorVar}];
89                    end
90                    [Field,ParamOut.VelType,errormsg]=read_civxdata(ObjectName,InputField,ParamIn.VelType);
91                    if ~isempty(errormsg)
92                        return
93                    end
94                    CivStage=Field.CivStage;
95                    ParamOut.CivStage=Field.CivStage;
96                end
97                ParamOut.FieldList=[{'image'};FieldList;{'get_field...'}];
98            end
99            if CivStage==0% read the field names on the interface get_field.
100                hget_field=findobj(allchild(0),'Name',GUIName);%find the get_field... GUI
101                if isempty(hget_field)% open the GUI get_field if it is not found
102                    hget_field= get_field(ObjectName);%open the get_field GUI
103                    set(hget_field,'Name',GUIName)%update the name of get_field (e.g. get_field_1)
104                end
105                hhget_field=guidata(hget_field);
106                %% update  the get_field GUI
107                set(hhget_field.inputfile,'String',ObjectName)
108                set(hhget_field.list_fig,'Value',1)
109                if exist('num','var')&&~isnan(num)
110                    set(hhget_field.TimeIndexValue,'String',num2str(num))
111                end
112                funct_list=get(hhget_field.ACTION,'UserData');
113                funct_index=get(hhget_field.ACTION,'Value');
114                funct=funct_list{funct_index};%select  the current action in get_field, e;g. PLOT
115                Field=funct(hget_field); %%activate the current action selected in get_field, e;g.read the names of the variables to plot
116                Tabchar={''};%default
117                Tabcell=[];
118                set(hhget_field.inputfile,'String',ObjectName)
119                if isfield(Field,'ListGlobalAttribute')&& ~isempty(Field.ListGlobalAttribute)
120                    for iline=1:length(Field.ListGlobalAttribute)
121                        Tabcell{iline,1}=Field.ListGlobalAttribute{iline};
122                        if isfield(Field, Field.ListGlobalAttribute{iline})
123                            eval(['val=Field.' Field.ListGlobalAttribute{iline} ';'])
124                            if ischar(val);
125                                Tabcell{iline,2}=val;
126                            else
127                                Tabcell{iline,2}=num2str(val);
128                            end
129                        end
130                    end
131                    if ~isempty(Tabcell)
132                        Tabchar=cell2tab(Tabcell,'=');
133                        Tabchar=[{''};Tabchar];
134                    end
135                end
136                ParamOut.CivStage=0;
137                ParamOut.VelType=[];
138                if isfield(Field,'TimeIndex')
139                    ParamOut.TimeIndex=Field.TimeIndex;
140                end
141                if isfield(Field,'TimeValue')
142                    ParamOut.TimeValue=Field.TimeValue;
143                end
144                ParamOut.FieldList={'get_field...'};
145            end
146        case {'video','mmreader'}
147            A=read(ObjectName,num);
148        case 'vol'
149            A=imread(ObjectName);
150            Npz=size(A,1)/ParamIn.Npy;
151            A=reshape(A',ParamIn.Npx,ParamIn.Npy,Npz);
152            A=permute(A,[3 2 1]);
153        case 'multimage'
154            warning 'off'
155            A=imread(ObjectName,num);
156        case 'image'
157            A=imread(ObjectName);
158    end
159catch ME
160    errormsg=ME.message;
161    return
162end
163
164%% case of image
165if ~isempty(A)
166    ParamOut.FieldName='image';
167    ParamOut.FieldList={'image'};
168    Npz=1;%default
169    npxy=size(A);
170%     Rangx=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
171%     Rangy=[npxy(1)-0.5 0.5]; %
172    Field.NbDim=2;%default
173    Field.AName='image';
174    Field.ListVarName={'AY','AX','A'}; %
175    if ndims(A)==3
176        if Npz==1;%color
177            Field.VarDimName={'AY','AX',{'AY','AX','rgb'}}; %
178            Field.AY=[npxy(1)-0.5 0.5];
179            Field.AX=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
180            ParamOut.Npx=npxy(2);% display image size on the interface
181            ParamOut.Npy=npxy(1);
182            Field.VarAttribute{3}.Mesh=1;
183        else
184            Field.NbDim=3;
185            Field.ListVarName=['AZ' Field.ListVarName];
186            Field.VarDimName={'AZ','AY','AX',{'AZ','AY','AX'}};
187            Field.AZ=[npxy(1)-0.5 0.5];
188            Field.AY=[npxy(2)-0.5 0.5];
189            Field.AX=[0.5 npxy(3)-0.5]; % coordinates of the first and last pixel centers
190            ParamOut.Npx=npxy(3);% display image size on the interface
191            ParamOut.Npy=npxy(2);
192            Field.VarAttribute{4}.Mesh=1;
193        end
194    else
195        Field.VarDimName={'AY','AX',{'AY','AX'}}; %
196        Field.AY=[npxy(1)-0.5 0.5];
197        Field.AX=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
198        ParamOut.Npx=npxy(2);% display image size on the interface
199        ParamOut.Npy=npxy(1);
200        Field.VarAttribute{3}.Mesh=1;
201    end
202    Field.A=A;
203    Field.CoordUnit='pixel'; %used for mouse_motion
204end
205
206
207
Note: See TracBrowser for help on using the repository browser.