Changeset 245 for trunk/src/series/sub_field_series.m
- Timestamp:
- Apr 20, 2011, 12:52:35 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/series/sub_field_series.m
r240 r245 68 68 itime=0; 69 69 NbSlice_calib={}; %test for z index 70 for iview=1:nbview%Loop on views 70 for iview=1:nbview%Loop on views (nbview=2) 71 71 XmlData{iview}=[];%default 72 72 filebase{iview}=fullfile(Series.RootPath{iview},Series.RootFile{iview}); 73 testxml(iview)=0;% test for xml file 73 74 if exist([filebase{iview} '.xml'],'file') 75 testxml(iview)=1; 74 76 [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']); 75 77 if isfield(XmlData{iview},'Time') … … 146 148 FieldName=''; 147 149 if strcmp(get(hseries.FieldMenu,'Visible'),'on') 148 Field_str=get(hseries.FieldMenu,'String');149 val=get(hseries.FieldMenu,'Value');150 FieldName=Field_str(val);%the same set of fields for all views151 VelType_str=get(hseries.VelTypeMenu,'String');152 VelType_val=get(hseries.VelTypeMenu,'Value');153 VelType=VelType_str{VelType_val}; %the same for all views154 if strcmp(FieldName,'')155 msgbox_uvmat('ERROR','no input field defined in FieldMenu')156 elseif strcmp(FieldName,'get_field...')157 hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI158 SubField=get_field('read_get_field',hObject,eventdata,hget_field); %read the names of the variables to plot in the get_field GUI159 end150 Field_str=get(hseries.FieldMenu,'String'); 151 val=get(hseries.FieldMenu,'Value'); 152 FieldName=Field_str(val);%the same set of fields for all views 153 VelType_str=get(hseries.VelTypeMenu,'String'); 154 VelType_val=get(hseries.VelTypeMenu,'Value'); 155 VelType=VelType_str{VelType_val}; %the same for all views 156 if strcmp(FieldName,'') 157 msgbox_uvmat('ERROR','no input field defined in FieldMenu') 158 elseif strcmp(FieldName,'get_field...') 159 hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI 160 SubField=get_field('read_get_field',hObject,eventdata,hget_field); %read the names of the variables to plot in the get_field GUI 161 end 160 162 end 161 163 %detect whether all the files are 'images' or 'netcdf' … … 187 189 testcivx=testnc; 188 190 end 191 if nbview~=2 192 msgbox_uvmat('ERROR','this function needs two input series as input') 193 return 194 elseif testima 195 answer=msgbox_uvmat('CONFIRMATION','this function will substract each of the second image series from the first one'); 196 if ~isequal(answer,'Yes') 197 return 198 end 199 else 200 answer=msgbox_uvmat('CONFIRMATION','this function will substract each the second field series from the first one'); 201 if ~isequal(answer,'Yes') 202 return 203 end 204 end 205 189 206 190 207 %% name of output files and directory: … … 193 210 RootPath=get(hseries.RootPath,'String'); 194 211 SubDir=get(hseries.SubDir,'String'); 195 if isequal(length(RootPath),1) 196 fulldir=RootPath{1}; 197 subdir='merge_proj'; 198 res_subdir=fullfile(fulldir,subdir); 199 else 200 def={fullfile(ProjectDir,'0_RESULTS')}; 201 dlgTitle='result directory'; 202 lineNo=1; 203 answer=msgbox_uvmat('INPUT_TXT',dlgTitle,def); 204 fulldir=answer{1}; 205 subdir=[]; 206 dirlist=sort(Series.RootFile); 207 for iview=1:nbview 208 if ~isempty(subdir) 209 subdir=[subdir '-']; 210 end 211 subdir=[subdir dirlist{iview}]; 212 end 213 res_subdir=fullfile(fulldir,subdir); 214 end 212 def={fullfile(ProjectDir,'0_RESULTS')}; 213 dlgTitle='result directory'; 214 lineNo=1; 215 answer=msgbox_uvmat('INPUT_TXT',dlgTitle,def); 216 fulldir=answer{1}; 217 subdir=[]; 218 dirlist=sort(Series.RootFile); 219 for iview=1:nbview 220 if ~isempty(subdir) 221 subdir=[subdir '-']; 222 end 223 subdir=[subdir dirlist{iview}]; 224 end 225 res_subdir=fullfile(fulldir,subdir); 226 215 227 ext=FileExt{1}; 216 228 if ~exist(fulldir,'dir') … … 236 248 end 237 249 filebasesub=fullfile(res_subdir,Series.RootFile{1}); 238 filebase_merge=fullfile(res_subdir,'merged');%root name for the merged files 250 filebase_merge=fullfile(res_subdir,'sub');%root name for the merged files 251 if testxml(1) && ( isempty(transform_fct)|| isequal(transform_fct,'px')) 252 copyfile([filebase{1} '.xml'],[filebase_merge '.xml'])% reproduce the xml file 253 display([filebase_merge '.xml copied from ' filebase{1} '.xml']) 254 end 239 255 240 256 %% MAIN LOOP … … 321 337 mergename=name_generator(filebase_merge,num_i1{1}(ifile),num_j1{1}(ifile),'.png',Series.NomType{1},1,num_i2{1}(ifile),num_j2{1}(ifile)); 322 338 if isa(Field{1}.A,'uint8') 323 imwrite(uint8(MergeData.A),mergename,'BitDepth',8); 339 imwrite(uint8(MergeData.A),mergename,'BitDepth',8); % transform in integers (and put to 0 the negative values) 324 340 elseif isa(Field{1}.A,'uint16') 325 341 imwrite(uint16(MergeData.A),mergename,'BitDepth',16); 326 342 end 327 % imwrite(MergeData.A,mergename,'BitDepth',bitdepth); 328 %write xml calibration file 329 siz=size(MergeData.A); 330 npy=siz(1); 331 npx=siz(2); 332 if isfield(MergeData,'VarAttribute')&&isfield(MergeData.VarAttribute{1},'Coord_2')&&isfield(MergeData.VarAttribute{1},'Coord_1') 333 Rangx=MergeData.VarAttribute{1}.Coord_2; 334 Rangy=MergeData.VarAttribute{1}.Coord_1; 335 elseif isfield(MergeData,'AX')&& isfield(MergeData,'AY') 336 Rangx=[MergeData.AX(1) MergeData.AX(end)]; 337 Rangy=[MergeData.AY(1) MergeData.AY(end)]; 338 else 339 Rangx=[0.5 npx-0.5]; 340 Rangy=[npy-0.5 0.5];%default 341 end 342 pxcmx=(npx-1)/(Rangx(2)-Rangx(1)); 343 pxcmy=(npy-1)/(Rangy(1)-Rangy(2)); 344 T_x=-pxcmx*Rangx(1)+0.5; 345 T_y=-pxcmy*Rangy(2)+0.5; 346 GeometryCal.focal=1; 347 GeometryCal.R=[pxcmx,0,0;0,pxcmy,0;0,0,1]; 348 GeometryCal.Tx_Ty_Tz=[T_x T_y 1]; 349 ImaDoc.GeometryCalib=GeometryCal; 350 t=struct2xml(ImaDoc); 351 t=set(t,1,'name','ImaDoc'); 352 save(t,[filebase_merge '.xml']) 353 display([filebase_merge '.xml saved']) 343 display(['output image ' mergename ' written']) 354 344 else 355 345 mergename=name_generator(filebase_merge,num_i1{1}(ifile),num_j1{1}(ifile),'.nc',Series.NomType{1},1,num_i2{1}(ifile),num_j2{1}(ifile)); … … 381 371 end 382 372 end 383 384 %'merge_field': concatene fields 385 %------------------------------------------------------------------------ 386 function MergeData=merge_field(Data) 387 %% default output 388 if isempty(Data)||~iscell(Data) 389 MergeData=[]; 390 return 391 end 392 MergeData=Data{1};%default 393 error=0; 394 nbview=length(Data); 395 if nbview==1 396 return 397 end 398 399 %% group the variables (fields of 'FieldData') in cells of variables with the same dimensions 400 [CellVarIndex,NbDim,VarTypeCell]=find_field_indices(Data{1}); 401 %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS 402 % CellVarIndex=cells of variable index arrays 403 ivar_new=0; % index of the current variable in the projected field 404 for icell=1:length(CellVarIndex) 405 if NbDim(icell)==1 406 continue 407 end 408 VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName 409 VarType=VarTypeCell{icell}; 410 ivar_X=VarType.coord_x; 411 ivar_Y=VarType.coord_y; 412 ivar_FF=VarType.errorflag; 413 if isempty(ivar_X) 414 test_grid=1;%test for input data on regular grid (e.g. image)coordinates 373 %write xml calibration file 374 if testima && ~isempty(transform_fct) && ~isequal(transform_fct,'px') 375 siz=size(MergeData.A); 376 npy=siz(1); 377 npx=siz(2); 378 if isfield(MergeData,'VarAttribute')&&isfield(MergeData.VarAttribute{1},'Coord_2')&&isfield(MergeData.VarAttribute{1},'Coord_1') 379 Rangx=MergeData.VarAttribute{1}.Coord_2; 380 Rangy=MergeData.VarAttribute{1}.Coord_1; 381 elseif isfield(MergeData,'AX')&& isfield(MergeData,'AY') 382 Rangx=[MergeData.AX(1) MergeData.AX(end)]; 383 Rangy=[MergeData.AY(1) MergeData.AY(end)]; 415 384 else 416 if length(ivar_Y)~=1 417 msgbox_uvmat('ERROR','y coordinate missing in proj_field.m') 418 return 419 end 420 test_grid=0; 421 end 422 %case of input fields with unstructured coordinates 423 if ~test_grid 424 for ivar=VarIndex 425 VarName=MergeData.ListVarName{ivar}; 426 for iview=1:nbview 427 eval(['MergeData.' VarName '=[MergeData.' VarName '; Data{iview}.' VarName '];']) 428 end 429 end 430 %case of fields defined on a structured grid 431 else 432 testFF=0; 433 for iview=2:nbview 434 for ivar=VarIndex 435 VarName=MergeData.ListVarName{ivar}; 436 if isfield(MergeData,'VarAttribute') 437 if length(MergeData.VarAttribute)>=ivar && isfield(MergeData.VarAttribute{ivar},'Role') && isequal(MergeData.VarAttribute{ivar}.Role,'errorflag') 438 testFF=1; 439 end 440 end 441 eval(['MergeData.' VarName '=MergeData.' VarName '+ Data{iview}.' VarName ';']) 442 end 443 end 444 if testFF 445 nbaver=nbview-MergeData.FF; 446 indgood=find(nbaver>0); 447 for ivar=VarIndex 448 VarName=MergeData.ListVarName{ivar}; 449 eval(['MergeData.' VarName '(indgood)=double(MergeData.' VarName '(indgood))./nbaver(indgood);']) 450 end 451 else 452 for ivar=VarIndex 453 VarName=MergeData.ListVarName{ivar}; 454 eval(['MergeData.' VarName '=double(MergeData.' VarName ')./nbview;']) 455 end 456 end 457 end 458 end 385 Rangx=[0.5 npx-0.5]; 386 Rangy=[npy-0.5 0.5];%default 387 end 388 pxcmx=(npx-1)/(Rangx(2)-Rangx(1)); 389 pxcmy=(npy-1)/(Rangy(1)-Rangy(2)); 390 T_x=-pxcmx*Rangx(1)+0.5; 391 T_y=-pxcmy*Rangy(2)+0.5; 392 GeometryCal.focal=1; 393 GeometryCal.R=[pxcmx,0,0;0,pxcmy,0;0,0,1]; 394 GeometryCal.Tx_Ty_Tz=[T_x T_y 1]; 395 ImaDoc.GeometryCalib=GeometryCal; 396 t=struct2xml(ImaDoc); 397 t=set(t,1,'name','ImaDoc'); 398 save(t,[filebase_merge '.xml']) 399 display([filebase_merge '.xml saved']) 400 end
Note: See TracChangeset
for help on using the changeset viewer.