Changeset 454 for trunk/src/series/ima_levels.m
- Timestamp:
- Jun 13, 2012, 5:04:14 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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)
Note: See TracChangeset
for help on using the changeset viewer.