- Timestamp:
- Jun 13, 2012, 5:04:14 PM (12 years ago)
- Location:
- trunk/src/series
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/series/aver_stat.m
r451 r454 63 63 % get the set of input file names (cell array filecell), and the lists of 64 64 % input file or frame indices i1_series,i2_series,j1_series,j2_series 65 65 66 [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); 67 66 68 % filecell{iview,fileindex}: cell array representing the list of file names 67 69 % iview: line in the table corresponding to a given file series … … 70 72 % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices 71 73 % set of frame indices used for movie or multimage input 72 if ~isempty(j1_series) 73 frame_index=j1_series; 74 else 75 frame_index=i1_series; 76 end 74 77 75 78 76 %% root input file(s) and type … … 88 86 NbSlice=Param.IndexRange.NbSlice; 89 87 end 90 nbview=size(i1_series,1);%number of input file series (lines in InputTable) 91 nbfield_j=size(i1_series,2); %nb of consecutive fields at each level(burst 92 nbfield=nbfield_j*size(i1_series,3); %total number of files or frames 93 nbfield_i=floor(nbfield/NbSlice);%total number of i indexes (adjusted to an integer number of slices) 94 nbfield=nbfield_i*nbfield_j; %total number of fields after adjustement 88 nbview=numel(i1_series);%number of input file series (lines in InputTable) 89 nbfield_j=size(i1_series{1},1); %nb of consecutive fields for the j index (bursts or volume slices) 90 nbfield_i=size(i1_series{1},2); %nb of consecutive fields for the i index 91 nbfield=nbfield_j*nbfield_i; %total number of files or frames 92 nbfield_i=floor(nbfield/NbSlice);%total number of indexes in a slice (adjusted to an integer number of slices) 93 nbfield=nbfield_i*NbSlice; %total number of fields after adjustement 95 94 96 95 %determine the file type on each line from the first input file … … 106 105 CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images 107 106 CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files 107 if ~isempty(j1_series{iview}) 108 frame_index{iview}=j1_series{iview}; 109 else 110 frame_index{iview}=i1_series{iview}; 111 end 108 112 end 109 113 … … 178 182 end 179 183 end 180 if size(time,2) < i2_series (1,end) || size(time,3) < j2_series(1,end)% time array absent or too short in ImaDoc xml file'184 if size(time,2) < i2_series{1}(end) || size(time,3) < j2_series{1}(end)% time array absent or too short in ImaDoc xml file' 181 185 time=[]; 182 186 end … … 279 283 280 284 %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%% 285 index 281 286 for iview=1:nbview 282 287 % reading input file(s) 283 [Data{iview},ParamOut,errormsg] = read_field(filecell{iview,index},FileType{iview},InputFields{iview},frame_index (iview,index));288 [Data{iview},ParamOut,errormsg] = read_field(filecell{iview,index},FileType{iview},InputFields{iview},frame_index{iview}(index)); 284 289 if ~isempty(errormsg) 285 290 errormsg=['error of input reading: ' errormsg]; … … 287 292 end 288 293 if ~isempty(NbSlice_calib) 289 Data{iview}.ZIndex=mod(i1_series (iview,index)-1,NbSlice_calib{1})+1;%Zindex for phys transform294 Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform 290 295 end 291 296 end … … 373 378 end 374 379 else % time from ImaDoc prevails 375 DataOut.Time=time(1,i1_series (1,1),j1_series(1,1));376 DataOut.Time_end=time(end,i1_series (end,end),j1_series(end,end));380 DataOut.Time=time(1,i1_series{1}(1),j1_series{1}(1)); 381 DataOut.Time_end=time(end,i1_series{end}(end),j1_series{end}(end)); 377 382 end 378 383 379 384 %writing the result file 380 OutputFile=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series (1,1),i1_series(1,end),i_slice,[]);385 OutputFile=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(1),i1_series{1}(end),i_slice,[]); 381 386 if CheckImage{1} %case of images 382 387 if isequal(FileInfo{1}.BitDepth,16)||(numel(FileInfo)==2 &&isequal(FileInfo{2}.BitDepth,16)) -
trunk/src/series/ima_levels.m
r447 r454 1 %'ima_levels': rescale the image intensity to reduce strong luminosity peaks 1 %'ima_levels': rescale the image intensity to reduce strong luminosity peaks (their blinking effects often perturbs PIV)) 2 % this function can be used as a template for applying a transform (here 'levels.m') on each image of a series 2 3 %------------------------------------------------------------------------ 3 % function GUI_input=ima_levels( num_i1,num_i2,num_j1,num_j2,Series)4 % function GUI_input=ima_levels(Param) 4 5 % 6 %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%% 5 7 %OUTPUT 6 8 % GUI_input=list of options in the GUI series.fig needed for the function 7 9 % 8 10 %INPUT: 9 %num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ) 10 %num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ) 11 %num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ ) 12 %num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ) 13 %Series: Matlab structure containing information set by the series interface% relabel_i_j: relabel an image series with two indices, according to the time matrix given by ImaDoc 14 %---------------------------------------------------------------------- 15 function GUI_input=ima_levels(Param) 16 %requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION) 17 if ~exist('Param','var') 18 GUI_input={'OutputDirExt';'.lev'}; 19 return %exit the function 11 % In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series. 12 % In batch mode, Param is the name of the corresponding xml file containing the same information 13 % In the absence of input (as activated when the current Action is selected 14 % in series), the function ouput GUI_input set the activation of the needed GUI elements 15 % 16 % Param contains the elements:(use the menu bar command 'export/GUI config' in series to see the current structure Param) 17 % .InputTable: cell of input file names, (several lines for multiple input) 18 % each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension} 19 % .OutputSubDir: name of the subdirectory for data outputs 20 % .OutputDir: directory for data outputs, including path 21 % .Action: .ActionName: name of the current activated function 22 % .ActionPath: path of the current activated function 23 % .IndexRange: set the file or frame indices on which the action must be performed 24 % .FieldTransform: .TransformName: name of the selected transform function 25 % .TransformPath: path of the selected transform function 26 % .TransformHandle: corresponding function handle 27 % .InputFields: sub structure describing the input fields withfields 28 % .FieldName: name of the field 29 % .VelType: velocity type 30 % .FieldName_1: name of the second field in case of two input series 31 % .VelType_1: velocity type of the second field in case of two input series 32 % .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object) 33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 34 35 function GUI_input=ima_levels (Param) 36 37 %% set the input elements needed on the GUI series when the action is selected in the menu ActionName 38 if ~exist('Param','var') % case with no input parameter 39 GUI_input={'NbViewMax';1;...% max nbre of input file series (default='' , no limitation) 40 'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default) 41 'NbSlice';'off'; ...%nbre of slices ('off' by default) 42 'VelType';'off';...% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) 43 'FieldName';'off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) 44 'FieldTransform'; 'off';...%can use a transform function 45 'ProjObject';'off';...%can use projection object(option 'off'/'on', 46 'Mask';'off';...%can use mask option (option 'off'/'on', 'off' by default) 47 'OutputDirExt';'.lev';...%set the output dir extension 48 ''}; 49 return 20 50 end 21 51 22 %% input parameters23 % read the xml file for batch case24 if ischar(Param) && ~isempty(find(regexp( 'Param','.xml$')))52 %% get input parameters, file names and indices 53 % BATCH case: read the xml file for batch case 54 if ischar(Param) && ~isempty(find(regexp(Param,'.xml$'))) 25 55 Param=xml2struct(Param); 26 56 checkrun=0; 27 else % RUN case: parameters introduced as the input structure Param 57 % RUN case: parameters introduced as the input structure Param 58 else 28 59 hseries=guidata(Param.hseries);%handles of the GUI series 29 WaitbarPos=get(hseries.waitbar_frame,'Position'); 30 checkrun=1; 60 WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series 61 checkrun=1; % indicate the RUN option is used 31 62 end 32 %filebase=fullfile(Param.InputTable{1,1},Param.InputTable{1,3}); 33 RootPath=Param.InputTable{1,1}; 34 Subdir=Param.InputTable{1,2}; 35 RootFile=Param.InputTable{1,3}; 36 NomType=Param.InputTable{1,4}; 37 FileExt=Param.InputTable{1,5}; 38 [filecell,i1_series,i2_series,j1_series]=get_file_series(Param);% list of input files and indices 39 if size(filecell,1)>1 40 msgbox_uvmat('WARNING','This function uses only the first input image series') 63 64 % get the set of input file names (cell array filecell), and the lists of 65 [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); 66 67 %% root input file(s) and type 68 RootPath=Param.InputTable(:,1); 69 RootFile=Param.InputTable(:,3); 70 SubDir=Param.InputTable(:,2); 71 NomType=Param.InputTable(:,4); 72 FileExt=Param.InputTable(:,5); 73 74 % numbers of slices and file indices 75 NbSlice=1;%default 76 if isfield(Param.IndexRange,'NbSlice') 77 NbSlice=Param.IndexRange.NbSlice; 78 end 79 nbview=numel(i1_series);%number of input file series (lines in InputTable) 80 nbfield_j=size(i1_series{1},1); %nb of consecutive fields for the j index (bursts or volume slices) 81 nbfield_i=size(i1_series{1},2); %nb of consecutive fields for the i index 82 nbfield=nbfield_j*nbfield_i; %total number of files or frames 83 nbfield_i=floor(nbfield/NbSlice);%total number of indexes in a slice (adjusted to an integer number of slices) 84 nbfield=nbfield_i*NbSlice; %total number of fields after adjustement 85 86 %determine the file type on each line from the first input file 87 ImageTypeOptions={'image','multimage','mmreader','video'};%allowed input file types(images) 88 [FileType{1},FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1}); 89 CheckImage{1}=~isempty(find(strcmp(FileType,ImageTypeOptions)));% =1 for images 90 if ~isempty(j1_series{1}) 91 frame_index{1}=j1_series{1}; 92 else 93 frame_index{1}=i1_series{1}; 94 end 95 96 %% calibration data and timing: read the ImaDoc files 97 %not relevant for this function 98 99 %% check coincidence in time for several input file series 100 %not relevant for this function 101 102 %% coordinate transform or other user defined transform 103 %not relevant for this function 104 105 %%%%%%%%%%%% END STANDARD PART %%%%%%%%%%%% 106 % EDIT FROM HERE 107 108 %% check the validity of input file types 109 if CheckImage{1} 110 FileExtOut='.png'; % write result as .png images for image inputs 111 if strcmp(lower(NomType{1}(end)),'a') 112 NomTypeOut=NomType{1}; 113 else 114 NomTypeOut='_1_1'; 115 end 116 else 117 msgbox_uvmat('ERROR',['invalid file type input: ' FileType{1} ' not an image']) 41 118 return 42 119 end 43 120 44 %% determine input image type 45 [FileType,FileInfo,MovieObject]=get_file_type(filecell{1,1}); 46 ListTypes={'image','multimage','mmreader','video'}; 121 %% Set field names and velocity types 122 %not relevant for this function 47 123 48 if isempty(strcmp(FileType,ListTypes))% if the detected FileType is not in the list for images 49 msgbox_uvmat('ERROR',['invalid file extension ' FileExt ': this function only accepts image or movie input']) 50 return 51 end 124 %% Initiate output fields 125 %not relevant for this function 52 126 53 %% create dir of the new images 54 SubdirResult=[Param.InputTable{1,2} '.lev'];% add the suffix '.lev' to the name of the image folder 55 try 56 mkdir(fullfile(Param.InputTable{1,1},SubdirResult)); 57 catch ME 58 msgbox_uvmat('ERROR',['error in creating result directory: ' ME.message]);%display error msg for directory creation if fails 59 return 60 end 61 [xx,msg2] = fileattrib(fullfile(Param.InputTable{1,1},SubdirResult),'+w','g'); %yield writing access (+w) to user group (g) 62 if ~strcmp(msg2,'') 63 msgbox_uvmat('ERROR',['pb of permission for ' fullfile(Param.InputTable{1,1},SubdirResult) ': ' msg2])%error message for directory creation 64 return 65 end 66 msgbox_uvmat('CONFIRMATION','apply image rescaling function levels.m '); 127 %% set processing parameters 128 % not needed for this function 67 129 68 %copy the xml file 69 % if exist([basename '.xml'],'file') 70 % copyfile([basename '.xml'],[basename_new '.xml']);% copy the .civ file 71 % end 130 %% update the xml file 131 % not needed for this function 72 132 73 %% main loop 74 nbfield=size(i1_series{1},2); 75 nbfield2=size(i1_series{1},1); 133 %% main loop on images 134 j1=[];%default 76 135 for ifile=1:nbfield 77 136 if checkrun 78 % update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield)79 137 update_waitbar(hseries.waitbar_frame,WaitbarPos,ifile/nbfield) 80 138 stopstate=get(hseries.RUN,'BusyAction'); … … 83 141 end 84 142 if isequal(stopstate,'queue') % enable STOP command 85 for jfile=1:nbfield2 86 %filename=name_generator(basename,num_i1(jfile,ifile),num_j1(jfile,ifile),Series.FileExt,Series.NomType); 87 %filename_new=name_generator(basename_new,num_i1(jfile,ifile),num_j1(jfile,ifile),'.png',Series.NomType); 88 filename=fullfile_uvmat(RootPath,Subdir,RootFile,FileExt,NomType,i1_series{1}(jfile,ifile),[],j1_series{1}(jfile,ifile)); 89 switch FileType 90 case {'video','mmreader'} 91 A=read(MovieObject,i1_series{1}(jfile,ifile)); 92 if strcmp(NomType,'*') 93 A=read(MovieObject,i1_series{1}(jfile,ifile)); 94 NomType_out='_1'; 95 else 96 A=imread(filename,j1_series{1}(jfile,ifile)); 97 NomType_out='_1_1'; 98 end 99 case {'vol','image'} 100 A=imread(filename); 101 NomType_out='_1'; 102 case 'multimage' 103 if strcmp(NomType,'*') 104 A=imread(filename,i1_series{1}(jfile,ifile)); 105 NomType_out='_1'; 106 else 107 A=imread(filename,j1_series{1}(jfile,ifile)); 108 NomType_out='_1_1'; 109 end 110 end 111 C=levels(A); 112 filename_new=fullfile_uvmat(RootPath,SubdirResult,RootFile,'.png',NomType_out,i1_series{1}(jfile,ifile),[],j1_series{1}(jfile,ifile)); 113 imwrite(C,filename_new) 114 display([filename_new ' written']) 143 if ~isempty(j1_series) 144 j1=j1_series{1}(ifile); 115 145 end 146 filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile),[],j1); 147 A=read_image(filename,FileType{1},MovieObject{1},frame_index{1}(ifile)); 148 if ndims(A)==3;%color images 149 A=sum(double(Aread),3);% take the sum of color components 150 end 151 % operation on images 152 A=levels(A); 153 filename_new=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1); 154 imwrite(A,filename_new) 155 display([filename_new ' written']) 116 156 end 117 157 end 118 158 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 159 119 160 120 161 function C=levels(A) -
trunk/src/series/sub_background.m
r451 r454 9 9 % luminosity, but it can be polluted by noise. 10 10 % Organization of image indices: 11 % The program is working on a series of images, labelled by two indices i and j, given 12 % by the input matlab vectors num_i1 and num_j1 respectively. In the list, j is the fastest increasing index. 13 % The processing can be done in slices (number nbslice), with bursts of 14 % nbfield2 successive images for a given slice (mode 'multilevel') 15 % In the mode 'volume', nbfield2=1 (1 image at each level) 16 17 % function GUI_input=sub_background(Param) 11 % The program is working on a series of images, 12 % The processing can be done over groups of nbfield2 consecutive files in slices (parameter NbSlice) 13 % In the mode 'volume', nbfield2=1 (1 image at each level)and NbSlice (=nbfield_j) 14 % Else nbfield2=nbfield_j =nbre of images in a burst (j index) 15 16 % function GUI_series_config=sub_background(Param) 18 17 % 19 18 %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%% 20 19 %OUTPUT 21 % GUI_ input=list of options in the GUI series.fig needed for the function20 % GUI_series_config=list of options in the GUI series.fig needed for the function 22 21 % 23 22 %INPUT: … … 25 24 % In batch mode, Param is the name of the corresponding xml file containing the same information 26 25 % In the absence of input (as activated when the current Action is selected 27 % in series), the function ouput GUI_ inputset the activation of the needed GUI elements26 % in series), the function ouput GUI_series_config set the activation of the needed GUI elements 28 27 % 29 28 % Param contains the elements:(use the menu bar command 'export/GUI config' in series to see the current structure Param) … … 47 46 48 47 49 function GUI_ input=sub_background (Param)48 function GUI_config=sub_background (Param,get_param) 50 49 51 50 %% set the input elements needed on the GUI series when the action is selected in the menu ActionName 52 51 if ~exist('Param','var') % case with no input parameter 53 GUI_ input={'NbViewMax';1;...% max nbre of input file series (default='' , no limitation)52 GUI_config={'NbViewMax';1;...% max nbre of input file series (default='' , no limitation) 54 53 'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default) 55 54 'NbSlice';'on'; ...%nbre of slices ('off' by default) … … 59 58 'ProjObject';'off';...%can use projection object(option 'off'/'on', 60 59 'Mask';'off';...%can use mask option (option 'off'/'on', 'off' by default) 61 'OutputDirExt';'.sb k';...%set the output dir extension60 'OutputDirExt';'.sback';...%set the output dir extension 62 61 ''}; 63 62 return … … 67 66 %% get input parameters, file names and indices 68 67 % BATCH case: read the xml file for batch case 69 if ischar(Param) && ~isempty(find(regexp(Param,'.xml$'))) 70 Param=xml2struct(Param); 71 checkrun=0; 72 % RUN case: parameters introduced as the input structure Param 73 else 68 if exist('get_param','var') && isequal(get_param,0) 69 checkrun=-1; %the function is just used to define to complement the input parameters 70 elseif ischar(Param) && ~isempty(find(regexp(Param,'.xml$'))) %batch mode 71 Param=xml2struct(Param); 72 checkrun=0; 73 % RUN case: parameters introduced as the input structure Param 74 else 74 75 hseries=guidata(Param.hseries);%handles of the GUI series 75 76 WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series … … 85 86 % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices 86 87 % set of frame indices used for movie or multimage input 87 if ~isempty(j1_series) 88 frame_index=j1_series; 89 else 90 frame_index=i1_series; 91 end 88 92 89 93 90 %% root input file(s) and type … … 103 100 NbSlice=Param.IndexRange.NbSlice; 104 101 end 105 nbview=size(i1_series,1);%number of input file series (lines in InputTable) 106 nbfield_j=size(i1_series,2); %nb of consecutive fields at each level(burst 107 nbfield=nbfield_j*size(i1_series,3); %total number of files or frames 108 nbfield_i=floor(nbfield/NbSlice);%total number of i indexes (adjusted to an integer number of slices) 109 nbfield=nbfield_i*nbfield_j; %total number of fields after adjustement 102 nbview=numel(i1_series);%number of input file series (lines in InputTable) 103 nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices) 104 nbfield_i=size(i1_series{1},2); %nb of fields for the i index 105 nbfield=nbfield_j*nbfield_i; %total number of fields 106 nbfield_i=floor(nbfield/NbSlice);%total number of indexes in a slice (adjusted to an integer number of slices) 107 nbfield=nbfield_i*NbSlice; %total number of fields after adjustement 110 108 111 109 %determine the file type on each line from the first input file 112 ImageTypeOptions={'image','multimage','mmreader','video'}; 113 NcTypeOptions={'netcdf','civx','civdata'}; 114 115 % % for iview=1:nbview 116 % if ~exist(filecell{iview,1}','file') 117 % msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist']) 118 % return 119 % end 120 % [FileType{iview},FileInfo{iview},Object{iview}]=get_file_type(filecell{iview,1}); 121 % CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images 122 % CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files 123 % end 124 125 [FileType,FileInfo,MovieObject]=get_file_type(filecell{1,1}); 126 CheckImage=~isempty(find(strcmp(FileType,ImageTypeOptions)));% =1 for images 110 ImageTypeOptions={'image','multimage','mmreader','video'};%allowed input file types(images) 111 112 [FileType{1},FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1}); 113 CheckImage{1}=~isempty(find(strcmp(FileType,ImageTypeOptions)));% =1 for images 114 if ~isempty(j1_series{1}) 115 frame_index{1}=j1_series{1}; 116 else 117 frame_index{1}=i1_series{1}; 118 end 127 119 128 120 %% calibration data and timing: read the ImaDoc files … … 139 131 140 132 %% check the validity of input file types 141 if CheckImage 133 if CheckImage{1} 142 134 FileExtOut='.png'; % write result as .png images for image inputs 143 NomTypeOut='_1_1'; 135 if strcmp(lower(NomType{1}(end)),'a') 136 NomTypeOut=NomType{1};%case of letter appendix 137 else 138 NomTypeOut='_1_1';% caseof purely numerical indexing 139 end 144 140 else 145 141 msgbox_uvmat('ERROR',['invalid file type input: ' FileType{1} ' not an image']) 146 142 return 147 143 end 148 %149 % NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series150 % if NbSlice~=nbfield_j151 % answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);152 % if ~strcmp(answer,'Yes')153 % return154 % end155 % end156 144 157 145 %% Set field names and velocity types 158 146 %not relevant here 159 160 147 161 148 %% Initiate output fields … … 164 151 %%% SPECIFIC PART BEGINS HERE 165 152 NbSlice=Param.IndexRange.NbSlice; %number of slices 166 siz=size(i1_series);153 %siz=size(i1_series); 167 154 nbaver_init=23;%approximate number of images used for the sliding background: to be adjusted later to include an integer number of bursts 168 155 j1=[];%default 169 156 170 %% apply the image rescaling function 'level' (avoid the blinking effects of bright particles)171 answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m after sub_background');172 test_level=isequal(answer,'Yes');173 174 157 %% adjust the proposed number of images in the sliding average to include an integer number of bursts 175 if siz(3)~=1176 nbaver=floor(nbaver_init/ siz(2)); % number of bursts used for the sliding background,158 if nbfield_i~=1 159 nbaver=floor(nbaver_init/nbfield_j); % number of bursts used for the sliding background, 177 160 if isequal(floor(nbaver/2),nbaver) 178 161 nbaver=nbaver+1;%put the number of burst to an odd number (so the middle burst is defined) 179 162 end 180 nbaver_init=nbaver* siz(2);%propose by default an integer number of bursts163 nbaver_init=nbaver*nbfield_j;%propose by default an integer number of bursts 181 164 end 182 165 183 166 %% set processing parameters 184 prompt = {'Number of images for the sliding background (MUST FIT IN COMPUETER MEMORY)';'The number of positions (laser slices)';'volume scan mode (Yes/No)';... 185 'the luminosity rank chosen to define the background (0.1=for dense particle seeding, 0.5 (median) for sparse particles'}; 186 dlg_title = ['get (slice by slice) a sliding background and substract to each image, result in subdir ' Param.OutputDir]; 187 num_lines= 3; 188 def = { num2str(nbaver_init);num2str(NbSlice);'No';'0.1'}; 189 answer = inputdlg(prompt,dlg_title,num_lines,def); 190 set(hseries.ParamVal,'String',answer([1 [3:4]])) 191 set(hseries.ParamVal,'Visible','on') 192 193 nbaver_ima=str2num(answer{1});%number of images for the sliding background 194 nbaver=ceil(nbaver_ima/siz(2));%number of bursts for the sliding background 195 if isequal(floor(nbaver/2),nbaver) 196 nbaver=nbaver+1;%put the number of burst to an odd number (so the middle burst is defined) 197 end 198 step=siz(2);%case of bursts: the sliding background is shifted by one burst 199 vol_test=answer{3}; 200 if isequal(vol_test,'Yes') 201 nbfield2=1;%case of volume: no consecutive series at a given level 202 NbSlice=siz(2);%number of slices 167 if checkrun ==-1 168 prompt = {'volume scan mode (Yes/No)';'Number of images for the sliding background (MUST FIT IN COMPUTER MEMORY)';... 169 'the luminosity rank chosen to define the background (0.1=for dense particle seeding, 0.5 (median) for sparse particles'}; 170 dlg_title = ['get (slice by slice) a sliding background and substract to each image, result in subdir ' Param.OutputDir]; 171 num_lines= 3; 172 def = { 'No';num2str(nbaver_init);'0.1'}; 173 answer = inputdlg(prompt,dlg_title,num_lines,def); 174 175 %check input consistency 176 if strcmp(answer{1},'No') && ~isequal(NbSlice,1) 177 check=msgbox_uvmat('INPUT_Y-N',['confirm the multi-level splitting into ' num2str(NbSlice) ' slices']); 178 if ~strcmp(check,'Yes') 179 return 180 end 181 end 182 if strcmp(answer{1},'Yes') 183 step=1; 184 else 185 step=nbfield_j;%case of bursts: the sliding background is shifted by the length of one burst 186 end 187 nbaver_ima=str2num(answer{2});%number of images for the sliding background 188 nbaver=ceil(nbaver_ima/step);%number of bursts for the sliding background 189 if isequal(floor(nbaver/2),nbaver) 190 nbaver=nbaver+1;%set the number of bursts to an odd number (so the middle burst is defined) 191 end 192 nbaver_ima=nbaver*step; 193 if nbaver_ima > nbfield 194 msgbox_uvmat('ERROR','number of images in a slice smaller than the proposed number of images for the sliding average') 195 return 196 end 197 GUI_config.CheckVolume=strcmp(answer{1},'Yes'); 198 GUI_config.SlidingSequenceSize=nbaver_ima; 199 GUI_config.BrightnessRankThreshold=str2num(answer{3}); 200 201 % apply the image rescaling function 'level' (avoid the blinking effects of bright particles) 202 answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m after sub_background'); 203 GUI_config.CheckLevelTransform=strcmp(answer,'Yes'); 204 205 % return to BATCH mode 206 if checkrun==-1 207 return %transfer to BATCH mode 208 end 203 209 else 204 nbfield2=siz(2); %nb of consecutive images at each level(burst) 205 if siz(3)>1 206 % NbSlice=str2num(answer{2})/(num_i1(1,2)-num_i1(1,1));% number of slices 207 NbSlice=str2num(answer{2})/(i1_series(1,1,2)-i1_series(1,1,1));% number of slices 210 GUI_config=Param.Specific; 211 if isequal(GUI_config.CheckVolume,1) 212 step=1; 208 213 else 209 NbSlice=1; 210 end 211 if ~isequal(floor(NbSlice),NbSlice) 212 msgbox_uvmat('ERROR','the number of slices must be a multiple of the i increment') 214 step=nbfield_j;%case of bursts: the sliding background is shifted by the length of one burst 215 end 216 nbaver_ima=GUI_config.SlidingSequenceSize;%number of images for the sliding background 217 nbaver=ceil(nbaver_ima/step);%number of bursts for the sliding background 218 if isequal(floor(nbaver/2),nbaver) 219 nbaver=nbaver+1;%set the number of bursts to an odd number (so the middle burst is defined) 220 end 221 nbaver_ima=nbaver*step; 222 if nbaver_ima > nbfield 223 msgbox_uvmat('ERROR','number of images in a slice smaller than the proposed number of images for the sliding average') 213 224 return 214 225 end 215 226 end 216 rank=floor(str2num(answer{4})*nbaver_ima); 227 228 % calculate absolute brightness rank 229 rank=floor(GUI_config.BrightnessRankThreshold*nbaver_ima); 217 230 if rank==0 218 231 rank=1;%rank selected in the sorted image series 219 232 end 220 lengthtot=siz(2)*siz(3);221 nbfield=floor(lengthtot/(nbfield2*NbSlice));%total number of i indexes (adjusted to an integer number of slices)222 nbfield_slice=nbfield*nbfield2;% number of fields per slice223 if nbaver_ima > nbfield*nbfield2224 msgbox_uvmat('ERROR','number of images in a slice smaller than the proposed number of images for the sliding average')225 return226 end227 nbfirst=(ceil(nbaver/2))*step;228 if nbfirst>nbaver_ima229 nbfirst=ceil(nbaver_ima/2);230 step=1;231 nbaver=nbaver_ima;232 end233 233 234 234 %% prealocate memory for the sliding background 235 Afirst=read_image(filecell{1,1},FileType{1},MovieObject,i1_series(1,1));236 [npy,npx]=size(Afirst);237 235 try 238 Ak=zeros(npy,npx,nbaver_ima,'uint16'); %prealocate memory 239 Asort=zeros(npy,npx,nbaver_ima,'uint16'); %prealocate memory 236 Afirst=read_image(filecell{1,1},FileType{1},MovieObject{1},frame_index{1}(1)); 237 [npy,npx]=size(Afirst); 238 if strcmp(class(Afirst),'uint8') % case of 8bit images 239 Ak=zeros(npy,npx,nbaver_ima,'uint8'); %prealocate memory 240 Asort=zeros(npy,npx,nbaver_ima,'uint8'); %prealocate memory 241 else 242 Ak=zeros(npy,npx,nbaver_ima,'uint16'); %prealocate memory 243 Asort=zeros(npy,npx,nbaver_ima,'uint16'); %prealocate memory 244 end 240 245 catch ME 241 246 msgbox_uvmat('ERROR',ME.message) … … 244 249 245 250 %% update the xml file 246 SubDirBase=regexprep(Param.InputTable{1,2},'\..*','');%take the root part of SubDir, before the first dot '.'247 filexml=fullfile(RootPath{1},[SubDirBase '.xml']);248 if ~exist(filexml,'file') && exist([filebase'.xml'],'file')% xml inside the image directory249 copyfile([filebase '.xml'],filexml);% copy the .xml file250 end251 if exist(filexml,'file')252 t=xmltree(filexml);253 %update information on the first image name in the series254 uid_Heading=find(t,'ImaDoc/Heading');255 if isempty(uid_Heading)256 [t,uid_Heading]=add(t,1,'element','Heading');257 end258 uid_ImageName=find(t,'ImaDoc/Heading/ImageName');259 if ~isempty(j1_series{1})260 j1=j1_series{1}(1);261 end262 ImageName=fullfile_uvmat([dir_images term],'',RootFile{1},'.png',NomType,i1_series(1,1),[],j1);263 [pth,ImageName]=fileparts(ImageName);264 ImageName=[ImageName '.png'];265 if isempty(uid_ImageName)266 [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');267 end268 uid_value=children(t,uid_ImageName);269 if isempty(uid_value)270 t=add(t,uid_ImageName,'chardata',ImageName);%indicate name of the first image, with ;png extension271 else272 t=set(t,uid_value(1),'value',ImageName);%indicate name of the first image, with ;png extension273 end274 275 %add information about image transform276 [t,new_uid]=add(t,1,'element','ImageTransform');277 [t,NameFunction_uid]=add(t,new_uid,'element','NameFunction');278 [t]=add(t,NameFunction_uid,'chardata','sub_background');279 if test_level280 [t,NameFunction_uid]=add(t,new_uid,'element','NameFunction');281 [t]=add(t,NameFunction_uid,'chardata','levels');282 end283 [t,NbSlice_uid]=add(t,new_uid,'element','NbSlice');284 [t]=add(t,new_uid,'chardata',num2str(NbSlice));285 [t,NbSlidingImages_uid]=add(t,new_uid,'element','NbSlidingImages');286 [t]=add(t,NbSlidingImages_uid,'chardata',num2str(nbaver));287 [t,LuminosityRank_uid]=add(t,new_uid,'element','RankBackground');288 [t]=add(t,LuminosityRank_uid,'chardata',num2str(rank));% luminosity rank almong the nbaver sliding images289 save(t,filexml)290 end251 % SubDirBase=regexprep(Param.InputTable{1,2},'\..*','');%take the root part of SubDir, before the first dot '.' 252 % filexml=fullfile(RootPath{1},[SubDirBase '.xml']); 253 % if ~exist(filexml,'file') && exist([fullfile(RootPath{1},SubDir{1},RootFile{1}) '.xml'],'file')% xml inside the image directory 254 % copyfile([filebase '.xml'],filexml);% copy the .xml file 255 % end 256 % if exist(filexml,'file') 257 % t=xmltree(filexml); 258 % %update information on the first image name in the series 259 % uid_Heading=find(t,'ImaDoc/Heading'); 260 % if isempty(uid_Heading) 261 % [t,uid_Heading]=add(t,1,'element','Heading'); 262 % end 263 % uid_ImageName=find(t,'ImaDoc/Heading/ImageName'); 264 % if ~isempty(j1_series{1}) 265 % j1=j1_series{1}(1); 266 % end 267 % ImageName=fullfile_uvmat([dir_images term],'',RootFile{1},'.png',NomType,i1_series(1,1),[],j1); 268 % [pth,ImageName]=fileparts(ImageName); 269 % ImageName=[ImageName '.png']; 270 % if isempty(uid_ImageName) 271 % [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName'); 272 % end 273 % uid_value=children(t,uid_ImageName); 274 % if isempty(uid_value) 275 % t=add(t,uid_ImageName,'chardata',ImageName);%indicate name of the first image, with ;png extension 276 % else 277 % t=set(t,uid_value(1),'value',ImageName);%indicate name of the first image, with ;png extension 278 % end 279 % 280 % %add information about image transform 281 % [t,new_uid]=add(t,1,'element','ImageTransform'); 282 % [t,NameFunction_uid]=add(t,new_uid,'element','NameFunction'); 283 % [t]=add(t,NameFunction_uid,'chardata','sub_background'); 284 % if GUI_config.CheckLevel 285 % [t,NameFunction_uid]=add(t,new_uid,'element','NameFunction'); 286 % [t]=add(t,NameFunction_uid,'chardata','levels'); 287 % end 288 % [t,NbSlice_uid]=add(t,new_uid,'element','NbSlice'); 289 % [t]=add(t,new_uid,'chardata',num2str(NbSlice)); 290 % [t,NbSlidingImages_uid]=add(t,new_uid,'element','NbSlidingImages'); 291 % [t]=add(t,NbSlidingImages_uid,'chardata',num2str(nbaver)); 292 % [t,LuminosityRank_uid]=add(t,new_uid,'element','RankBackground'); 293 % [t]=add(t,LuminosityRank_uid,'chardata',num2str(rank));% luminosity rank almong the nbaver sliding images 294 % save(t,filexml) 295 % end 291 296 %copy the mask 292 297 % if exist([filebase '_1mask_1'],'file') … … 297 302 for islice=1:NbSlice 298 303 %% select the series of image indices at the level islice 299 for ifield=1:nbfield 300 for iburst=1:nbfield2 301 indselect(iburst,ifield)=((ifield-1)*NbSlice+(islice-1))*nbfield2+iburst; 302 end 304 indselect=islice:NbSlice*step:nbfield;% select file indices of the slice 305 for ifield=1:step-1 306 indselect=[indselect;indselect(end,:)+1]; 303 307 end 304 308 … … 307 311 ifile=indselect(ifield); 308 312 filename=filecell{1,ifile}; 309 Aread=read_image(filename,FileType,MovieObject,i1_series{1}(ifile)); 313 Aread=read_image(filename,FileType{1},MovieObject{1},frame_index{1}(ifile)); 314 if ndims(Aread)==3;%color images 315 Aread=sum(double(Aread),3);% take the sum of color components 316 end 310 317 Ak(:,:,ifield)=Aread; 311 318 end … … 313 320 B=Asort(:,:,rank);%background image 314 321 display( 'first background image will be substracted') 322 nbfirst=(ceil(nbaver/2))*step; 315 323 for ifield=1:nbfirst 316 324 Acor=double(Ak(:,:,ifield))-double(B);%substract background to the current image 317 325 Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor 318 C=uint16(Acor);% set to integer 16 bits319 326 ifile=indselect(ifield); 320 % newname=name_generator(filebase_b,num_i1(ifile),num_j1(ifile),'.png',NomType)% makes the new file name321 327 if ~isempty(j1_series{1}) 322 328 j1=j1_series{1}(ifile); 323 329 end 324 newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series (1,ifile),[],i_slice,[]);325 % newname=fullfile_uvmat(RootPath{1},SubdirResult,RootFile{1},'.png',NomType,i1_series{1}(ifile),[],j1); 326 % newname=name_generator(filebase_b,i1_series{1}(ifile),j1_series{1}(ifile),'.png',NomType);% makes the new file name327 if test_level328 C=levels( C);330 newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1); 331 332 %write result file 333 if GUI_config.CheckLevelTransform 334 C=levels(Acor); 329 335 imwrite(C,newname,'BitDepth',8); % save the new image 330 336 else 331 imwrite(C,newname,'BitDepth',16); % save the new image 332 end 333 end 334 335 %% repeat the operation on a sliding series of nbaver*nbfield2 images 337 if isequal(FileInfo{1}.BitDepth,16) 338 C=uint16(Acor); 339 imwrite(C,newname,'BitDepth',16); % save the new image 340 else 341 C=uint8(Acor); 342 imwrite(C,newname,'BitDepth',8); % save the new image 343 end 344 end 345 display([newname ' written']) 346 end 347 348 %% repeat the operation on a sliding series of images 336 349 display('sliding background image will be substracted') 337 if nbfield_ slice> nbaver_ima338 for ifield = step*ceil(nbaver/2)+1:step:nbfield_ slice-step*floor(nbaver/2)350 if nbfield_i > nbaver_ima 351 for ifield = step*ceil(nbaver/2)+1:step:nbfield_i-step*floor(nbaver/2) 339 352 if checkrun 340 353 stopstate=get(hseries.RUN,'BusyAction'); 341 update_waitbar(hseries.waitbar_frame,WaitbarPos,(ifield+(islice-1)*nbfield_ slice)/(nbfield_slice*NbSlice))354 update_waitbar(hseries.waitbar_frame,WaitbarPos,(ifield+(islice-1)*nbfield_i)/(nbfield_i*NbSlice)) 342 355 else 343 356 stopstate='queue'; … … 348 361 for iburst=1:step 349 362 ifile=indselect(ifield+step*floor(nbaver/2)+iburst-1); 350 filename=fullfile_uvmat(RootPath{1},SubDir,RootFile{1},FileExt,NomType,i1_series(1,ifile),[],j1_series(1,ifile)); 351 %filename=name_generator(filebase,num_i1(ifile),num_j1(ifile),FileExt,NomType); 352 Aread=read_image(filename,FileType,MovieObject,i1_series(1,ifile)); 363 filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile),[],j1_series{1}(ifile)); 364 Aread=read_image(filename,FileType{1},MovieObject{1},i1_series{1}(ifile)); 365 if ndims(Aread)==3;%color images 366 Aread=sum(double(Aread),3);% take the sum of color components 367 end 353 368 Ak(:,:,nbaver_ima-step+iburst)=Aread; 354 369 end … … 359 374 Acor=double(Ak(:,:,index))-double(B); 360 375 Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor 361 C=uint16(Acor);362 376 ifile=indselect(ifield+iburst-1); 363 377 if ~isempty(j1_series{1}) 364 378 j1=j1_series{1}(ifile); 365 379 end 366 newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series(1,1),[],i_slice,[]); 367 % newname=fullfile_uvmat(Param.InputTable{1,1},SubdirResult,Param.InputTable{1,3},'.png',NomType,i1_series{1}(ifile),[],j1); 368 %[newname]=name_generator(filebase_b,num_i1(ifile),num_j1(ifile),'.png',NomType) % makes the new file name 369 if test_level 370 C=levels(C); 380 newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1); 381 %write result file 382 if GUI_config.CheckLevelTransform 383 C=levels(Acor); 371 384 imwrite(C,newname,'BitDepth',8); % save the new image 372 385 else 373 imwrite(C,newname,'BitDepth',16); % save the new image 386 if isequal(FileInfo{1}.BitDepth,16) 387 C=uint16(Acor); 388 imwrite(C,newname,'BitDepth',16); % save the new image 389 else 390 C=uint8(Acor); 391 imwrite(C,newname,'BitDepth',8); % save the new image 392 end 374 393 end 394 display([newname ' written']) 395 375 396 end 376 397 else … … 382 403 %% substract the background from the last images 383 404 display('last background image will be substracted') 384 ifield=nbfield_ slice-(step*ceil(nbaver/2))+1:nbfield_slice;385 for ifield=nbfield_ slice-(step*floor(nbaver/2))+1:nbfield_slice386 index=ifield-nbfield_ slice+step*(2*floor(nbaver/2)+1);405 ifield=nbfield_i-(step*ceil(nbaver/2))+1:nbfield_i; 406 for ifield=nbfield_i-(step*floor(nbaver/2))+1:nbfield_i 407 index=ifield-nbfield_i+step*(2*floor(nbaver/2)+1); 387 408 Acor=double(Ak(:,:,index))-double(B); 388 409 Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor 389 C=uint16(Acor);390 410 ifile=indselect(ifield); 391 411 if ~isempty(j1_series{1}) 392 412 j1=j1_series{1}(ifile); 393 413 end 394 newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series(1,ifile),[],j1); 395 % newname=fullfile_uvmat(Param.InputTable{1,1},SubdirResult,Param.InputTable{1,3},'.png',NomType,i1_series{1}(ifile),[],j1); 396 if test_level 397 C=levels(C); 414 newname=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1); 415 416 %write result file 417 if GUI_config.CheckLevelTransform 418 C=levels(Acor); 398 419 imwrite(C,newname,'BitDepth',8); % save the new image 399 420 else 400 imwrite(C,newname,'BitDepth',16); % save the new image 401 end 421 if isequal(FileInfo{1}.BitDepth,16) 422 C=uint16(Acor); 423 imwrite(C,newname,'BitDepth',16); % save the new image 424 else 425 C=uint8(Acor); 426 imwrite(C,newname,'BitDepth',8); % save the new image 427 end 428 end 429 display([newname ' written']) 402 430 end 403 431 end … … 406 434 if checkrun 407 435 update_waitbar(hseries.waitbar,WaitbarPos,1) 408 end409 410 %------------------------------------------------------------------------411 %--read images and convert them to the uint16 format used for PIV412 function A=read_image(FileName,FileType,VideoObject,num)413 %------------------------------------------------------------------------414 %num is the view number needed for an avi movie415 switch FileType416 case {'video','mmreader'}417 A=read(VideoObject,num);418 case 'multimage'419 A=imread(FileName,num);420 case 'image'421 A=imread(FileName);422 end423 siz=size(A);424 if length(siz)==3;%color images425 A=sum(double(A),3);% take the sum of color components426 436 end 427 437
Note: See TracChangeset
for help on using the changeset viewer.