source: trunk/src/series/float_tracking.m @ 1134

Last change on this file since 1134 was 1127, checked in by g7moreau, 12 months ago

Update Joel email

File size: 12.3 KB
RevLine 
[619]1% function ParamOut=particle_tracking(Param)
2%
3% Method:
4   
5% Organization of image indices:
6   
7%INPUT:
8% num_i1: matrix of image indices i
9% num_j1: matrix of image indices j, must be the same size as num_i1
10% num_i2 and num_j2: not used for a function acting on images
11% Series: matlab structure containing parameters, as defined by the interface UVMAT/series
12%       Series.RootPath{1}: path to the image series
13%       Series.RootFile{1}: root file name
14%       Series.FileExt{1}: image file extension
15%       Series.NomType{1}: nomenclature type for file in
16%
17% Method:
18%       Series.NbSlice: %number of slices defined on the interface
19% global A rangx0 rangy0 minA maxA; % make current image A accessible in workspace
20% global hfig1 hfig2 scalar
21% global Abackg nbpart lum diam
[984]22%%%%%%%%%%%%%%ᅵ
[619]23%
24%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
25%
26%OUTPUT
27% ParamOut: sets options in the GUI series.fig needed for the function
28%
29%INPUT:
30% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
31% In batch mode, Param is the name of the corresponding xml file containing the same information
32% when Param.Action.RUN=0 (as activated when the current Action is selected
33% in series), the function ouput paramOut set the activation of the needed GUI elements
34%
35% Param contains the elements:(use the menu bar command 'export/GUI config' in series to
36% see the current structure Param)
37%    .InputTable: cell of input file names, (several lines for multiple input)
38%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
39%    .OutputSubDir: name of the subdirectory for data outputs
40%    .OutputDirExt: directory extension for data outputs
41%    .Action: .ActionName: name of the current activated function
42%             .ActionPath:   path of the current activated function
43%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
44%             .RUN =0 for GUI input, =1 for function activation
45%             .RunMode='local','background', 'cluster': type of function  use
46%             
47%    .IndexRange: set the file or frame indices on which the action must be performed
48%    .FieldTransform: .TransformName: name of the selected transform function
49%                     .TransformPath:   path  of the selected transform function
50%    .InputFields: sub structure describing the input fields withfields
51%              .FieldName: name(s) of the field
52%              .VelType: velocity type
53%              .FieldName_1: name of the second field in case of two input series
54%              .VelType_1: velocity type of the second field in case of two input series
55%              .Coord_y: name of y coordinate variable
56%              .Coord_x: name of x coordinate variable
57%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
58%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59
[810]60%=======================================================================
[1126]61% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
[810]62%   http://www.legi.grenoble-inp.fr
[1127]63%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
[810]64%
65%     This file is part of the toolbox UVMAT.
66%
67%     UVMAT is free software; you can redistribute it and/or modify
68%     it under the terms of the GNU General Public License as published
69%     by the Free Software Foundation; either version 2 of the license,
70%     or (at your option) any later version.
71%
72%     UVMAT is distributed in the hope that it will be useful,
73%     but WITHOUT ANY WARRANTY; without even the implied warranty of
74%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
75%     GNU General Public License (see LICENSE.txt) for more details.
76%=======================================================================
77
[619]78function ParamOut=particle_tracking(Param)
79
80%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
81if isstruct(Param) && isequal(Param.Action.RUN,0)
82    % general settings of the GUI:
83    ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
84    ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
85    ParamOut.NbSlice='off'; %nbre of slices ('off' by default)
86    ParamOut.VelType='off';% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
87    ParamOut.FieldName='off';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
88    ParamOut.FieldTransform = 'off';%can use a transform function
89    ParamOut.ProjObject='off';%can use projection object(option 'off'/'on',
90    ParamOut.Mask='off';%can use mask option   (option 'off'/'on', 'off' by default)
91    ParamOut.OutputDirExt='.track';%set the output dir extension
92    ParamOut.OutputFileMode='NbSlice';% '=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice
93    filecell=get_file_series(Param);%check existence of the first input file
94    if ~exist(filecell{1,1},'file')
95        msgbox_uvmat('WARNING','the first input file does not exist')
96    end
97    % parameters specific to the function 'particle_tracking'
[804]98        Par.Nblock=10;%size of image subblocks for background determination, =[]: no sublock
99    Par.ThreshLum=210;% luminosity threshold for particle detection, < 0 for black particles, >0 for white particles
100  ParamOut.ActionInput=Par;
[619]101    return
102end
103
104%%%%%%%%%%%%  STANDARD RUN PART  %%%%%%%%%%%%
105ParamOut=[];
106%% read input parameters from an xml file if input is a file name (batch mode)
107checkrun=1;
108if ischar(Param)
109    Param=xml2struct(Param);% read Param as input file (batch case)
110    checkrun=0;
111end
[804]112hseries=findobj(allchild(0),'Tag','series');
113RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
114WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
[619]115
116%% define the directory for result file
117OutputDir=[Param.OutputSubDir Param.OutputDirExt];
118
119%% root input file(s) name, type and index series
120RootPath=Param.InputTable{1,1};
121RootFile=Param.InputTable{1,3};
122SubDir=Param.InputTable{1,2};
123NomType=Param.InputTable{1,4};
124FileExt=Param.InputTable{1,5};
125[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
126%%%%%%%%%%%%
127% The cell array filecell is the list of input file names, while
128% filecell{iview,fileindex}:
129%        iview: line in the table corresponding to a given file series
130%        fileindex: file index within  the file series,
131% 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
132% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
133%%%%%%%%%%%%
134nbview=numel(i1_series);%number of input file series (lines in InputTable)
135nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
136nbfield_i=size(i1_series{1},2); %nb of fields for the i index
137nbfield=nbfield_j*nbfield_i; %total number of fields
138
139%% frame index for movie or multimage file input 
140if ~isempty(j1_series{1})
141    frame_index=j1_series{1};
142else
143    frame_index=i1_series{1};
144end
145
146%% check the input file type 
[784]147[FileInfo,VideoObject]=get_file_info(filecell{1,1});
[783]148FileType=FileInfo.FileType;
[984]149ImageTypeOptions={'image','multimage','mmreader','video','cine_phantom'};
[619]150if isempty(find(strcmp(FileType,ImageTypeOptions)))
151    disp('input file not images')
152    return
153end
154
155%% calibration data and timing: read the ImaDoc files
156[XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series);
157
158%%%%%%%%%%%%   SPECIFIC PART (to edit) %%%%%%%%%%%%
159%filter for particle center of mass(luminosity)
160%Nblock=Param.ActionInput.Nblock;
[804]161ThreshLum=Param.ActionInput.ThreshLum;% luminosity threshold for particle detection, < 0 for black particles, >0 for white particles
162%AbsThreshold=30; %threshold below which a pixel is considered belonging to a float
[619]163SizePart=4;
164%
165hh=ones(5,5);
166hh(1,1)=0;
167hh(1,5)=0;% sum luminosity on the 5x5 domain without corners
168hh(5,1)=0;
169hh(5,5)=0;
170hdx=[-2:1:2];
171hdy=[-2:1:2];
172[hdX,hdY]=meshgrid(hdx,hdy);
173hdX(1,1)=0;
174hdX(1,5)=0;% sum luminosity on the 5x5 domain -corners
175hdX(5,1)=0;
176hdX(5,5)=0;
177hdY(1,1)=0;
178hdY(1,5)=0;% sum luminosity on the 5x5 domain -corners
179hdY(5,1)=0;
180hdY(5,5)=0;
181
182%% detection of particles on the first image
183
184%%%%%% MAIN LOOP ON FRAMES %%%%%%
185for ifile=1:nbfield
186    if checkrun
[804]187                update_waitbar(WaitbarHandle,ifile/nbfield)
188        if ~isempty(RUNHandle) &&ishandle(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
189            disp('program stopped by user')
190            return
[619]191        end
192    end
193    j1=[];
194    if ~isempty(j1_series)&&~isequal(j1_series,{[]})
195        j1=j1_series{1}(ifile);
196    end
197    filename=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,i1_series{1}(ifile),[],j1);
198    A=read_image(filename,FileType,VideoObject,frame_index(ifile));% read the current frame
199    if ndims(A)==3;%color images
200        A=sum(double(A),3);% take the sum of color components
201    end
202        %%  mask to reduce the  working area (optional)
203    Mask=ones(size(A));
204    Mask(1:SizePart,:)=0;
205    Mask(end-SizePart:end,:)=0;
206    Mask(:,1:SizePart)=0;
207    Mask(:,end-SizePart:end)=0; 
208    if ifile ==1
[804]209        if ThreshLum>0 %brigth particles
210        [Js,Is]=find(A>ThreshLum & Mask==1);%indices (I,J) of dark pixels
211        else %black particle
212               [Js,Is]=find(A<ThreshLum & Mask==1);%indices (I,J) of dark pixels
213        end
[619]214    else
215        Is=round(Xtime(ifile-1,:));
216        Js=round(Ytime(ifile-1,:));
217    end
218    X=zeros(size(Is));
219    Y=zeros(size(Js));
220    F=zeros(size(Js));
221    for ipart=1:numel(Is)
222        if Mask(Js(ipart),Is(ipart))==1
223            subimage=A(Js(ipart)-SizePart:Js(ipart)+SizePart,Is(ipart)-SizePart:Is(ipart)+SizePart);
224            subimage=max(max(subimage))-subimage;%take negative of the image
225            [vector,F(ipart)] = SUBPIX2DGAUSS (subimage,SizePart+1,SizePart+1);
226            %             X0(ipart)=Is(ipart);%TEST
227            %             Y0(ipart)=Js(ipart);%TEST
228            X(ipart)=Is(ipart)+vector(1);%corrected position
229            Y(ipart)=Js(ipart)+vector(2);
230            Xround=round(X(ipart));
231            Yround=round(Y(ipart));
232            if ifile==1
233                Mask(Yround-SizePart:Yround+SizePart,Xround-SizePart:Xround+SizePart)=0;% mask the subregion already treated to
234                % avoid double counting
235            end
236        end
237    end
238    %             X0=X0(X>0);
239    %     Y0=Y0(Y>0);
240    if ifile ==1
241        Ftime(1,:)=F(X>0);
242        Xtime(1,:)=X(X>0);
243        Ytime(1,:)=Y(Y>0);
244    else
245        Ftime(ifile,:)=F;
246        Xtime(ifile,:)=X;
247        Ytime(ifile,:)=Y;
248    end
249end
250figure(1)
251plot(Xtime)
252figure(2)
253plot(Ytime)
254
255%------------------------------------------------------------------------
256% --- Find the maximum of the correlation function after interpolation
257function [vector,F] = SUBPIX2DGAUSS (result_conv,x,y)
258%------------------------------------------------------------------------
259vector=[0 0]; %default
260F=-2;
261peaky=y;
262peakx=x;
263[npy,npx]=size(result_conv);
264if (x <= npx-1) && (y <= npy-1) && (x >= 1) && (y >= 1)
265    F=0;
266    for i=-1:1
267        for j=-1:1
268            %following 15 lines based on
269            %H. Nobach ï¿œ M. Honkanen (2005)
270            %Two-dimensional Gaussian regression for sub-pixel displacement
271            %estimation in particle image velocimetry or particle position
272            %estimation in particle tracking velocimetry
273            %Experiments in Fluids (2005) 38: 511ï¿œ515
274            c10(j+2,i+2)=i*log(result_conv(y+j, x+i));
275            c01(j+2,i+2)=j*log(result_conv(y+j, x+i));
276            c11(j+2,i+2)=i*j*log(result_conv(y+j, x+i));
277            c20(j+2,i+2)=(3*i^2-2)*log(result_conv(y+j, x+i));
278            c02(j+2,i+2)=(3*j^2-2)*log(result_conv(y+j, x+i));
279        end
280    end
281    c10=(1/6)*sum(sum(c10));
282    c01=(1/6)*sum(sum(c01));
283    c11=(1/4)*sum(sum(c11));
284    c20=(1/6)*sum(sum(c20));
285    c02=(1/6)*sum(sum(c02));
286    deltax=(c11*c01-2*c10*c02)/(4*c20*c02-c11^2);
287    deltay=(c11*c10-2*c01*c20)/(4*c20*c02-c11^2);
288    if abs(deltax)<1
289        peakx=x+deltax;
290    end
291    if abs(deltay)<1
292        peaky=y+deltay;
293    end
294end
295vector=[peakx-floor(npx/2)-1 peaky-floor(npy/2)-1];
296
Note: See TracBrowser for help on using the repository browser.