Changeset 245 for trunk/src/series
- Timestamp:
- Apr 20, 2011, 12:52:35 PM (14 years ago)
- Location:
- trunk/src/series
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/series/calc_background.m
r239 r245 182 182 % ifile=indselect(ifield); 183 183 filename=name_generator(filebase,num_i1(ifile),num_j1(ifile),Series.FileExt,Series.NomType) 184 Aread=read_image(filename,FileType,num_i1(ifile),MovieObject); 184 try 185 Aread=read_image(filename,FileType,num_i1(ifile),MovieObject); 186 catch ME 187 msgbox_uvmat('ERROR',ME.message) 188 return 189 end 185 190 Ak(:,:,ifile)=Aread; 186 191 %finish the waitbar -
trunk/src/series/relabel_i_j.m
r223 r245 1 2 % relabel_i_j: relabel an image series with two indices, and correct errors from the RDvision transfer program 1 %'relabel_i_j': relabel an image series with two indices, and correct errors from the RDvision transfer program 3 2 %---------------------------------------------------------------------- 4 3 function GUI_input=relabel_i_j(num_i1,num_i2,num_j1,num_j2,Series) … … 26 25 end 27 26 basename=fullfile(RootPath{1},RootFile{1}); 28 [XmlData,warntext]=imadoc2struct([basename '.xml']) ;% read the xml file appended to the present function (containing bug corrections)27 [XmlData,warntext]=imadoc2struct([basename '.xml'])% read the xml file appended to the present function (containing bug corrections) 29 28 if ~isempty(warntext) 30 29 msgbox_uvmat('ERROR',warntext)%error message for xml file reading … … 32 31 nbfield1=size(XmlData.Time,1); 33 32 nbfield2=size(XmlData.Time,2); 34 35 33 set(hseries.first_i,'String',num2str(first_label))% display the first image in the process 36 34 set(hseries.last_i,'String',num2str(nbfield1*nbfield2-1+first_label))% display the last image in the process … … 38 36 SeriesData=get(hGUI,'UserData'); 39 37 if ~strcmp(SeriesData.NomType,'_000001') 40 msgbox_uvmat('WARNING','the input is not a file from RDvision: this function relabel_i_j has no action') %error message for directory creation38 msgbox_uvmat('WARNING','the input is not a file from RDvision: this function relabel_i_j has no action');%error message for directory creation 41 39 return 42 40 else 43 msgbox_uvmat('CONFIRMATION','this function will relabel the file series from RDvision and correct the xml file')%error message for directory creation 41 answer=msgbox_uvmat('','this function will relabel the file series from RDvision and correct the xml file');%error message for directory creation 42 if ~strcmp(answer,'Yes') 43 return 44 end 44 45 end 45 46 … … 48 49 return 49 50 end 50 answer=msgbox_uvmat('CONFIRMATION',[num2str(nbfield1) ' bursts containing ' num2str(nbfield2) ' images each']);%error message for directory creation 51 if nbfield2>=2 52 answer=msgbox_uvmat('',[num2str(nbfield1) ' bursts containing ' num2str(nbfield2) ' images each']);%error message for directory creation 53 nomtype='_i_j'; 54 else 55 answer=msgbox_uvmat('',['image series with ' num2str(nbfield1) ' images']);%error message for directory creation 56 nomtype='_i'; 57 end 58 if ~strcmp(answer,'Yes') 59 return 60 end 51 61 52 62 %% copy and adapt the xml file … … 54 64 try 55 65 copyfile([basename '.xml'],[basename '.xml~']);% backup the xml file 56 catch 57 errormsg=lasterr 58 msgbox_uvmat('ERROR',errormsg); 66 catch ME 67 msgbox_uvmat('ERROR',ME.message); 59 68 return 60 69 end … … 81 90 82 91 %%%% correction RDvision %%%% 92 if isfield(XmlData,'NbDtj') 83 93 uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj'); 84 94 uid_value=children(t,uid_NbDtj); … … 86 96 t=set(t,uid_value(1),'value',num2str(XmlData.NbDtj)); 87 97 end 98 end 99 if isfield(XmlData,'NbDtk') 88 100 uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk'); 89 101 uid_value=children(t,uid_NbDtk); … … 91 103 t=set(t,uid_value(1),'value',num2str(XmlData.NbDtk)); 92 104 end 105 end 106 if strcmp(nomtype,'_i') && isfield(XmlData,'NbDti') 107 uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti'); 108 uid_value=children(t,uid_NbDti); 109 if ~isempty(uid_value) 110 t=set(t,uid_value(1),'value',num2str(XmlData.NbDti)); 111 end 112 uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj'); 113 uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk'); 114 t=delete(t,uid_NbDtj); 115 t=delete(t,uid_NbDtk); 116 uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj'); 117 uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk'); 118 t=delete(t,uid_Dtj); 119 t=delete(t,uid_Dtk); 120 end 93 121 %%% 94 122 … … 97 125 98 126 %% main loop 127 99 128 for ifile=1:nbfield1*nbfield2 100 129 update_waitbar(hseries.waitbar,WaitbarPos,ifile/(nbfield1*nbfield2)) … … 102 131 num_j=mod(ifile-1+first_label,nbfield2)+1; 103 132 num_i=floor((ifile-1+first_label)/nbfield2)+1; 104 filename_new=name_generator(basename,num_i,num_j,'.png', '_i_j');133 filename_new=name_generator(basename,num_i,num_j,'.png',nomtype); 105 134 try 106 135 movefile(filename,filename_new); … … 115 144 return 116 145 end 117 % if test_level 118 % A=imread(filename); 119 % C=levels(A); 120 % imwrite(C,filename_new) 121 % else 122 % try 123 % copyfile(filename,filename_new); 124 % catch 125 % errormsg=lasterr 126 % msgbox_uvmat('ERROR',errormsg); 127 % return 128 % end 129 % end 130 end 131 132 133 function C=levels(A) 134 %whos A; 135 B=double(A(:,:,1)); 136 windowsize=round(min(size(B,1),size(B,2))/20); 137 windowsize=floor(windowsize/2)*2+1; 138 ix=[1/2-windowsize/2:-1/2+windowsize/2];% 139 %del=np/3; 140 %fct=exp(-(ix/del).^2); 141 fct2=cos(ix/(windowsize-1)/2*pi/2); 142 %Mfiltre=(ones(5,5)/5^2); 143 %Mfiltre=fct2'; 144 Mfiltre=fct2'*fct2; 145 Mfiltre=Mfiltre/(sum(sum(Mfiltre))); 146 147 C=filter2(Mfiltre,B); 148 C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize); 149 C(:,end-windowsize+1:end)=C(:,end-windowsize+1)*ones(1,windowsize); 150 C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:); 151 C(end-windowsize+1:end,:)=ones(windowsize,1)*C(end-windowsize,:); 152 C=tanh(B./(2*C)); 153 [n,c]=hist(reshape(C,1,[]),100); 154 % figure;plot(c,n); 155 156 [m,i]=max(n); 157 c_max=c(i); 158 [dummy,index]=sort(abs(c-c(i))); 159 n=n(index); 160 c=c(index); 161 i_select = find(cumsum(n)<0.95*sum(n)); 162 if isempty(i_select) 163 i_select = 1:length(c); 164 end 165 c_select=c(i_select); 166 n_select=n(i_select); 167 cmin=min(c_select); 168 cmax=max(c_select); 169 C=(C-cmin)/(cmax-cmin)*256; 170 C=uint8(C); 146 end 147 171 148 172 149 %'imadoc2struct': reads the xml file for image documentation … … 256 233 NbDtj=get_value(subt,'/BurstTiming/NbDtj',1); 257 234 %%%% correction RDvision %%%% 258 NbDtj=NbDtj/numel(Dtj); 259 s.NbDtj=NbDtj; 260 %%%% 261 Dti=get_value(subt,'/BurstTiming/Dti',[]); 235 % NbDtj=NbDtj/numel(Dtj); 236 % s.NbDtj=NbDtj; 237 % %%%% 238 Dti=get_value(subt,'/BurstTiming/Dti',[]) 239 NbDti=get_value(subt,'/BurstTiming/NbDti',1) 240 %%%% correction RDvision %%%% 241 if isempty(Dti)% series 242 Dti=Dtj 243 NbDti=NbDtj 244 Dtj=[]; 245 s.Dti=Dti; 246 'TESTrxml' 247 s.NbDti=NbDti 248 else 249 NbDtj=NbDtj/numel(Dtj);%bursts 250 s.NbDtj=NbDtj; 251 end 252 %%%% %%%% 262 253 Dti=Dti/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's') 263 NbDti=get_value(subt,'/BurstTiming/NbDti',1); 254 264 255 Time_val=get_value(subt,'/BurstTiming/Time',0);%time in TimeUnit 265 256 if ~isempty(Dti) -
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.