source: trunk/src/series/ima_levels.m @ 624

Last change on this file since 624 was 624, checked in by sommeria, 11 years ago

waitbar system for series improved to aloow use as stand alone fcts.

to add at the head of series fcts:
hseries=findobj(allchild(0),'Tag','series');
RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
WaitbarHandle?=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series

call to waitbar:

update_waitbar(WaitbarHandle?,index/nbfield)
if ishandle(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction?'),'queue')

disp('program stopped by user')
break

end

File size: 9.3 KB
RevLine 
[454]1%'ima_levels': rescale the image intensity to reduce strong luminosity peaks (their blinking effects often perturbs PIV))
[457]2% this function can be used as a template for applying a transform (here 'levels.m') to each image of a series
[171]3%------------------------------------------------------------------------
[454]4% function GUI_input=ima_levels(Param)
[171]5%
[604]6%------------------------------------------------------------------------
[454]7%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
[457]8%
[171]9%OUTPUT
[604]10% ParamOut: sets options in the GUI series.fig needed for the function
[171]11%
12%INPUT:
[454]13% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
14% In batch mode, Param is the name of the corresponding xml file containing the same information
[604]15% when Param.Action.RUN=0 (as activated when the current Action is selected
16% in series), the function ouput paramOut set the activation of the needed GUI elements
[454]17%
[604]18% Param contains the elements:(use the menu bar command 'export/GUI config' in series to
19% see the current structure Param)
[454]20%    .InputTable: cell of input file names, (several lines for multiple input)
21%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
22%    .OutputSubDir: name of the subdirectory for data outputs
[604]23%    .OutputDirExt: directory extension for data outputs
[454]24%    .Action: .ActionName: name of the current activated function
25%             .ActionPath:   path of the current activated function
[604]26%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
27%             .RUN =0 for GUI input, =1 for function activation
28%             .RunMode='local','background', 'cluster': type of function  use
29%             
[454]30%    .IndexRange: set the file or frame indices on which the action must be performed
31%    .FieldTransform: .TransformName: name of the selected transform function
32%                     .TransformPath:   path  of the selected transform function
33%    .InputFields: sub structure describing the input fields withfields
[604]34%              .FieldName: name(s) of the field
[454]35%              .VelType: velocity type
36%              .FieldName_1: name of the second field in case of two input series
37%              .VelType_1: velocity type of the second field in case of two input series
[604]38%              .Coord_y: name of y coordinate variable
39%              .Coord_x: name of x coordinate variable
[454]40%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
41%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 
[592]43function ParamOut=ima_levels (Param)
[454]44
[606]45%% set the input elements needed on the GUI series when the action is selected in the menu ActionName or InputTable refreshed
[592]46if isstruct(Param) && isequal(Param.Action.RUN,0)
[604]47    ParamOut.NbViewMax=1;% max nbre of input file series (default , no limitation)
[592]48    ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
49    ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
50    ParamOut.NbSlice='off'; %nbre of slices ('off' by default)
51    ParamOut.VelType='off';% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
52    ParamOut.FieldName='one';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
53    ParamOut.FieldTransform = 'off';%can use a transform function
54    ParamOut.ProjObject='off';%can use projection object(option 'off'/'on',
55    ParamOut.Mask='off';%can use mask option   (option 'off'/'on', 'off' by default)
56    ParamOut.OutputDirExt='.lev';%set the output dir extension
[604]57    ParamOut.OutputFileMode='NbInput';% ='=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice
58    %check the type of the existence and type of the first input file:
59    Param.IndexRange.last_i=Param.IndexRange.first_i;%keep only the first index in the series
[606]60    if isfield(Param.IndexRange,'first_j')
[604]61    Param.IndexRange.last_j=Param.IndexRange.first_j;
[606]62    end
[604]63    filecell=get_file_series(Param);
64    if ~exist(filecell{1,1},'file')
65        msgbox_uvmat('WARNING','the first input file does not exist')
66    else
67        FileType=get_file_type(filecell{1,1});
68        if isempty(find(strcmp(FileType,{'image','multimage','mmreader','video'})));% =1 for images
69            msgbox_uvmat('ERROR',['bad input file type for ' mfilename ': an image is needed'])
70        end
71    end
[592]72return
[64]73end
74
[457]75%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
[592]76%% read input parameters from an xml file if input is a file name (batch mode)
[624]77ParamOut=[];
[592]78checkrun=1;
[457]79if ischar(Param)
[592]80    Param=xml2struct(Param);% read Param as input file (batch case)
81    checkrun=0;
[442]82end
[624]83hseries=findobj(allchild(0),'Tag','series');
84RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
85WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
[64]86
[624]87%% subdirectory for output files
88SubdirOut=[Param.OutputSubDir Param.OutputDirExt];
89
[604]90%% root input file names and nomenclature type (cell arrays with one element)
[454]91RootPath=Param.InputTable(:,1);
92RootFile=Param.InputTable(:,3);
93SubDir=Param.InputTable(:,2);
94NomType=Param.InputTable(:,4);
95FileExt=Param.InputTable(:,5);
96
[604]97
98%% get the set of input file names (cell array filecell), and file indices
[457]99[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
100% filecell{iview,fileindex}: cell array representing the list of file names
101%        iview: line in the table corresponding to a given file series
102%        fileindex: file index within  the file series,
103% i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j
104% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
[604]105nbfield_j=size(j1_series{1},1); %nb of fields for the j index (bursts or volume slices)
[457]106nbfield_i=size(i1_series{1},2); %nb of fields for the i index
107nbfield=nbfield_j*nbfield_i; %total number of fields
[604]108[FileType{1},FileInfo{1},VideoObject{1}]=get_file_type(filecell{1,1});% type of input file
[442]109
[604]110%% frame index for movie or multimage file input 
[454]111if ~isempty(j1_series{1})
112    frame_index{1}=j1_series{1};
113else
114    frame_index{1}=i1_series{1};
[442]115end
[454]116
117%% calibration data and timing: read the ImaDoc files
118%not relevant for this function
119
120%% check coincidence in time for several input file series
121%not relevant for this function
122
123%% coordinate transform or other user defined transform
124%not relevant for this function
125
126%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
127 % EDIT FROM HERE
128
[604]129 %% Extension and indexing nomenclature for output file
130 FileExtOut='.png'; % write result as .png images for image inputs
131 if strcmpi(NomType{1}(end),'a')
132     NomTypeOut=NomType{1};
133 else
134     NomTypeOut='_1_1';
135 end
[64]136
[454]137%% Set field names and velocity types
138%not relevant for this function
[64]139
[454]140%% Initiate output fields
141%not relevant for this function
142
143%% set processing parameters
144% not needed for this function
145
146%% update the xml file
147% not needed for this function
148
149%% main loop on images
150j1=[];%default
[64]151for ifile=1:nbfield
[624]152            update_waitbar(WaitbarHandle,index/nbfield)
153    if ishandle(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
154        disp('program stopped by user')
155        return
[64]156    end
[604]157    if ~isequal(stopstate,'queue') % enable STOP command
158        break
159    end
160    if ~isempty(j1_series)&&~isequal(j1_series,{[]})
161        j1=j1_series{1}(ifile);
162    end
163    filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile),[],j1);
164    A=read_image(filename,FileType{1},VideoObject{1},frame_index{1}(ifile));
165    if ndims(A)==3;%color images
166        A=sum(double(Aread),3);% take the sum of color components
167    end
168    % operation on images
169    A=levels(A);
170    % write output file
171    filename_new=fullfile_uvmat(RootPath{1},SubdirOut,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
172    imwrite(A,filename_new)
173    display([filename_new ' written'])
[64]174end
[442]175%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[64]176
[454]177
[64]178function C=levels(A)
179%whos A;
180B=double(A(:,:,1));
181windowsize=round(min(size(B,1),size(B,2))/20);
182windowsize=floor(windowsize/2)*2+1;
183ix=[1/2-windowsize/2:-1/2+windowsize/2];%
184%del=np/3;
185%fct=exp(-(ix/del).^2);
186fct2=cos(ix/(windowsize-1)/2*pi/2);
187%Mfiltre=(ones(5,5)/5^2);
188%Mfiltre=fct2';
189Mfiltre=fct2'*fct2;
190Mfiltre=Mfiltre/(sum(sum(Mfiltre)));
191
[71]192C=filter2(Mfiltre,B);
[64]193C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize);
194C(:,end-windowsize+1:end)=C(:,end-windowsize+1)*ones(1,windowsize);
195C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:);
196C(end-windowsize+1:end,:)=ones(windowsize,1)*C(end-windowsize,:);
197C=tanh(B./(2*C));
198[n,c]=hist(reshape(C,1,[]),100);
199% figure;plot(c,n);
200
201[m,i]=max(n);
202c_max=c(i);
203[dummy,index]=sort(abs(c-c(i)));
204n=n(index);
205c=c(index);
206i_select = find(cumsum(n)<0.95*sum(n));
207if isempty(i_select)
208    i_select = 1:length(c);
209end
210c_select=c(i_select);
211n_select=n(i_select);
212cmin=min(c_select);
213cmax=max(c_select);
214C=(C-cmin)/(cmax-cmin)*256;
215C=uint8(C);
Note: See TracBrowser for help on using the repository browser.