[921] | 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 |
---|
| 22 | %%%%%%%%%%%%%%ᅵ |
---|
| 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 | |
---|
| 60 | %======================================================================= |
---|
[1071] | 61 | % Copyright 2008-2020, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
[921] | 62 | % http://www.legi.grenoble-inp.fr |
---|
| 63 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
| 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 | |
---|
| 78 | function ParamOut=particle_tracking(Param) |
---|
| 79 | |
---|
| 80 | %% set the input elements needed on the GUI series when the action is selected in the menu ActionName |
---|
| 81 | if 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='.patch';%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 |
---|
| 98 | prompt = {'threshold value'}; |
---|
| 99 | dlg_title = 'get threshold'; |
---|
| 100 | num_lines= 1; |
---|
| 101 | def = { '0'}; |
---|
| 102 | answer = inputdlg(prompt,dlg_title,num_lines,def); |
---|
| 103 | if isempty(answer) |
---|
| 104 | return |
---|
| 105 | end |
---|
| 106 | ParamOut.ActionInput.LumThreshold=str2double(answer{1}); |
---|
| 107 | |
---|
| 108 | return |
---|
| 109 | end |
---|
| 110 | |
---|
| 111 | %%%%%%%%%%%% STANDARD RUN PART %%%%%%%%%%%% |
---|
| 112 | ParamOut=[]; |
---|
| 113 | %% read input parameters from an xml file if input is a file name (batch mode) |
---|
| 114 | checkrun=1; |
---|
| 115 | if ischar(Param) |
---|
| 116 | Param=xml2struct(Param);% read Param as input file (batch case) |
---|
| 117 | checkrun=0; |
---|
| 118 | end |
---|
| 119 | hseries=findobj(allchild(0),'Tag','series'); |
---|
| 120 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series |
---|
| 121 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series |
---|
| 122 | |
---|
| 123 | %% define the directory for result file |
---|
| 124 | OutputDir=[Param.OutputSubDir Param.OutputDirExt]; |
---|
| 125 | |
---|
| 126 | %% root input file(s) name, type and index series |
---|
| 127 | RootPath=Param.InputTable{1,1}; |
---|
| 128 | RootFile=Param.InputTable{1,3}; |
---|
| 129 | SubDir=Param.InputTable{1,2}; |
---|
| 130 | NomType=Param.InputTable{1,4}; |
---|
| 131 | FileExt=Param.InputTable{1,5}; |
---|
| 132 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
---|
| 133 | %%%%%%%%%%%% |
---|
| 134 | % The cell array filecell is the list of input file names, while |
---|
| 135 | % filecell{iview,fileindex}: |
---|
| 136 | % iview: line in the table corresponding to a given file series |
---|
| 137 | % fileindex: file index within the file series, |
---|
| 138 | % 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 |
---|
| 139 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices |
---|
| 140 | %%%%%%%%%%%% |
---|
| 141 | nbview=numel(i1_series);%number of input file series (lines in InputTable) |
---|
| 142 | nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices) |
---|
| 143 | nbfield_i=size(i1_series{1},2); %nb of fields for the i index |
---|
| 144 | nbfield=nbfield_j*nbfield_i; %total number of fields |
---|
| 145 | |
---|
| 146 | %% frame index for movie or multimage file input |
---|
| 147 | if ~isempty(j1_series{1}) |
---|
| 148 | frame_index=j1_series{1}; |
---|
| 149 | else |
---|
| 150 | frame_index=i1_series{1}; |
---|
| 151 | end |
---|
| 152 | |
---|
| 153 | %% check the input file type |
---|
| 154 | [FileInfo,VideoObject]=get_file_info(filecell{1,1}); |
---|
| 155 | FileType=FileInfo.FileType; |
---|
[984] | 156 | ImageTypeOptions={'image','multimage','mmreader','video','cine_phantom'}; |
---|
[921] | 157 | if isempty(find(strcmp(FileType,ImageTypeOptions))) |
---|
| 158 | disp('input file not images') |
---|
| 159 | return |
---|
| 160 | end |
---|
| 161 | |
---|
| 162 | %% calibration data and timing: read the ImaDoc files |
---|
| 163 | [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series); |
---|
| 164 | |
---|
| 165 | %%%%%%%%%%%% SPECIFIC PART (to edit) %%%%%%%%%%%% |
---|
| 166 | %filter for particle center of mass(luminosity) |
---|
| 167 | |
---|
| 168 | Threshold=Param.ActionInput.LumThreshold;% luminosity threshold for particle detection, < 0 for black particles, >0 for white particles |
---|
| 169 | |
---|
| 170 | %% fixed mask to avoid tube image |
---|
| 171 | Amask=imread('/fsnet/project/coriolis/2015/15MINI_MEDDY/0_REF_FILES/mask_patch.png'); |
---|
| 172 | |
---|
| 173 | %% initiate output statistics data |
---|
| 174 | Data.ListVarName={'Time','z','Area', 'MajorAxisLength' , 'MinorAxisLength'}; |
---|
| 175 | Data.VarDimName={'Time','z',{'Time','z'},{'Time','z'},{'Time','z'}}; |
---|
| 176 | Data.Time = 1:nbfield_i; %default |
---|
| 177 | Data.z=1:nbfield_j; |
---|
| 178 | Data.Area=zeros(nbfield_i,nbfield_j); |
---|
| 179 | Data.MajorAxisLength=zeros(nbfield_i,nbfield_j); |
---|
| 180 | Data.MinorAxisLength=zeros(nbfield_i,nbfield_j); |
---|
| 181 | |
---|
| 182 | %%%%%% MAIN LOOP ON FRAMES %%%%%% |
---|
| 183 | for ifile=1:nbfield |
---|
| 184 | if checkrun |
---|
| 185 | update_waitbar(WaitbarHandle,ifile/nbfield) |
---|
| 186 | if ~isempty(RUNHandle) &&ishandle(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue') |
---|
| 187 | disp('program stopped by user') |
---|
| 188 | return |
---|
| 189 | end |
---|
| 190 | end |
---|
| 191 | i1=i1_series{1}(ifile); |
---|
| 192 | j1=1; |
---|
| 193 | if ~isempty(j1_series)&&~isequal(j1_series,{[]}) |
---|
| 194 | j1=j1_series{1}(ifile); |
---|
| 195 | end |
---|
| 196 | filename=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,i1,[],j1); |
---|
| 197 | A=read_image(filename,FileType,VideoObject,frame_index(ifile));% read the current frame |
---|
| 198 | |
---|
| 199 | A=(A>Threshold) & Amask>100;%transform to binary image format |
---|
| 200 | try |
---|
| 201 | STATS = regionprops(A, 'FilledArea','MinorAxisLength','MajorAxisLength','PixelIdxList'); |
---|
| 202 | Area=zeros(size(STATS)); |
---|
| 203 | for iobj=1:numel(STATS) |
---|
| 204 | Area(iobj)=STATS(iobj).FilledArea; |
---|
| 205 | end |
---|
| 206 | [Data.Area(i1,j1), main_obj]=max(Area); |
---|
| 207 | Data.MajorAxisLength(i1,j1)=STATS(main_obj).MajorAxisLength; |
---|
| 208 | Data.MinorAxisLength(i1,j1)=STATS(main_obj).MinorAxisLength; |
---|
| 209 | for iobj=1:numel(STATS) |
---|
| 210 | if iobj~=main_obj |
---|
| 211 | A(STATS(iobj).PixelIdxList)=0; |
---|
| 212 | end |
---|
| 213 | end |
---|
| 214 | |
---|
| 215 | catch ME |
---|
| 216 | disp('image toolbox not available, program stopped') |
---|
| 217 | % return |
---|
| 218 | end |
---|
| 219 | filename_out=fullfile_uvmat(RootPath,OutputDir,RootFile,'.png',NomType,i1,[],j1); |
---|
| 220 | imwrite(255*A,filename_out,'BitDepth',8) |
---|
| 221 | disp([filename_out ' written']) |
---|
| 222 | end |
---|
| 223 | |
---|
| 224 | %% record time series of stat |
---|
| 225 | [filename_nc,idetect]=name_generator(RootPath,OutputDir,RootFile,'.nc','_i1-i2',1,nbfield_i) |
---|
| 226 | errormsg=struct2nc(filename_nc,Data); |
---|
| 227 | |
---|
| 228 | if isempty(errormsg) |
---|
| 229 | [filename_nc ' written'] |
---|
| 230 | else |
---|
| 231 | disp(errormsg) |
---|
| 232 | end |
---|
| 233 | |
---|