source: trunk/src/series/particle_tracking.m @ 616

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

particle_tracking added, cleaning for other functions in 'series'

File size: 21.1 KB
Line 
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   dexing
19%       Series.NbSlice: %number of slices defined on the interface
20% global A rangx0 rangy0 minA maxA; % make current image A accessible in workspace
21% global hfig1 hfig2 scalar
22% global Abackg nbpart lum diam
23%%%%%%%%%%%%%%ù
24%
25%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
26%
27%OUTPUT
28% ParamOut: sets options in the GUI series.fig needed for the function
29%
30%INPUT:
31% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
32% In batch mode, Param is the name of the corresponding xml file containing the same information
33% when Param.Action.RUN=0 (as activated when the current Action is selected
34% in series), the function ouput paramOut set the activation of the needed GUI elements
35%
36% Param contains the elements:(use the menu bar command 'export/GUI config' in series to
37% see the current structure Param)
38%    .InputTable: cell of input file names, (several lines for multiple input)
39%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
40%    .OutputSubDir: name of the subdirectory for data outputs
41%    .OutputDirExt: directory extension for data outputs
42%    .Action: .ActionName: name of the current activated function
43%             .ActionPath:   path of the current activated function
44%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
45%             .RUN =0 for GUI input, =1 for function activation
46%             .RunMode='local','background', 'cluster': type of function  use
47%             
48%    .IndexRange: set the file or frame indices on which the action must be performed
49%    .FieldTransform: .TransformName: name of the selected transform function
50%                     .TransformPath:   path  of the selected transform function
51%    .InputFields: sub structure describing the input fields withfields
52%              .FieldName: name(s) of the field
53%              .VelType: velocity type
54%              .FieldName_1: name of the second field in case of two input series
55%              .VelType_1: velocity type of the second field in case of two input series
56%              .Coord_y: name of y coordinate variable
57%              .Coord_x: name of x coordinate variable
58%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
59%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60
61function ParamOut=particle_tracking(Param)
62
63%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
64if isstruct(Param) && isequal(Param.Action.RUN,0)
65    % general settings of the GUI:
66    ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
67    ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
68    ParamOut.NbSlice='off'; %nbre of slices ('off' by default)
69    ParamOut.VelType='off';% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
70    ParamOut.FieldName='off';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
71    ParamOut.FieldTransform = 'off';%can use a transform function
72    ParamOut.ProjObject='off';%can use projection object(option 'off'/'on',
73    ParamOut.Mask='off';%can use mask option   (option 'off'/'on', 'off' by default)
74    ParamOut.OutputDirExt='.track';%set the output dir extension
75    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
76    filecell=get_file_series(Param);%check existence of the first input file
77    if ~exist(filecell{1,1},'file')
78        msgbox_uvmat('WARNING','the first input file does not exist')
79    end
80    return
81    % parameters specific to the function 'particle_tracking'
82    %Par.Nblock=25;%size of image subblocks for analysis
83    Par.Nblock=[];%no subblock for background determination
84    % Numexp=inputdlg('Entrer le numero','numexp',1);
85    % numexp=str2num(Numexp{1})
86    % Thresh=inputdlg('Entrer le seuil de luminosite (4000)','thresh',1);
87    % thresh=str2num(Thresh{1});%threshold for detection of particle luminosity weight
88    %filter particle detection
89    Par.ThreshLum=-2000;% luminosity threshold for particle detection, < 0 for black particles, >0 for white particles
90    ParamOut.ActionInput=Par;
91end
92
93%%%%%%%%%%%%  STANDARD RUN PART  %%%%%%%%%%%%
94ParamOut=[];
95%% read input parameters from an xml file if input is a file name (batch mode)
96checkrun=1;
97if ischar(Param)
98    Param=xml2struct(Param);% read Param as input file (batch case)
99    checkrun=0;
100end
101
102%% define the directory for result file
103OutputDir=[Param.OutputSubDir Param.OutputDirExt];
104
105%% root input file(s) name, type and index series
106RootPath=Param.InputTable{1,1};
107RootFile=Param.InputTable{1,3};
108SubDir=Param.InputTable{1,2};
109NomType=Param.InputTable{1,4};
110FileExt=Param.InputTable{1,5};
111[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
112%%%%%%%%%%%%
113% The cell array filecell is the list of input file names, while
114% filecell{iview,fileindex}:
115%        iview: line in the table corresponding to a given file series
116%        fileindex: file index within  the file series,
117% 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
118% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
119%%%%%%%%%%%%
120nbview=numel(i1_series);%number of input file series (lines in InputTable)
121nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
122nbfield_i=size(i1_series{1},2); %nb of fields for the i index
123nbfield=nbfield_j*nbfield_i; %total number of fields
124[first_i,tild,last_i,first_j,tild,last_j,errormsg]=get_index_range(Param.IndexRange);
125if ~isempty(errormsg),display(errormsg),return,end
126
127%% check the input file type 
128[FileType,FileInfo,MovieObject]=get_file_type(filecell{1,1});
129ImageTypeOptions={'image','multimage','mmreader','video'};
130if isempty(find(strcmp(FileType,ImageTypeOptions)))
131    disp('input file not images')
132    return
133end
134
135%% calibration data and timing: read the ImaDoc files
136[XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series);
137
138%%%%%%%%%%%%   SPECIFIC PART (to edit) %%%%%%%%%%%%
139%filter for particle center of mass(luminosity)
140Nblock=Param.InputAction.Nblock;
141ThreshLum=Param.InputAction.ThreshLum;% luminosity threshold for particle detection, < 0 for black particles, >0 for white particles
142
143hh=ones(5,5);
144hh(1,1)=0;
145hh(1,5)=0;% sum luminosity on the 5x5 domain without corners
146hh(5,1)=0;
147hh(5,5)=0;
148hdx=[-2:1:2];
149hdy=[-2:1:2];
150[hdX,hdY]=meshgrid(hdx,hdy);
151hdX(1,1)=0;
152hdX(1,5)=0;% sum luminosity on the 5x5 domain -corners
153hdX(5,1)=0;
154hdX(5,5)=0;
155hdY(1,1)=0;
156hdY(1,5)=0;% sum luminosity on the 5x5 domain -corners
157hdY(5,1)=0;
158hdY(5,5)=0;
159%Parameters for image plotting
160pxcm=1;
161pycm=1;%scaling
162PlotParam.AutoScal=0;
163PlotParam.MaxA=700;
164PlotParam.MinA=0;
165PlotParam.BW=1;
166PlotParam.Contours=0;
167
168%%%%%%%%%%%%%%
169% sizfiles=size(num_j1)
170% nbfield=sizfiles(1); %number of images in a burst
171% %%%%%%%%%
172% hRUN=findobj(Series.hseries,'Tag','RUN');
173% hwaitbar=findobj(Series.hseries,'Tag','waitbar');%handles of the waitbar
174% waitbarpos(1)=Series.WaitbarPos(1);%x position of the waitbar
175% waitbarpos(3)=Series.WaitbarPos(3);% width of the waitbar
176% filebase=fullfile(Series.RootPath{1},Series.RootFile{1});
177% dir_images=Series.RootPath{1};
178% nom_type=Series.NomType{1};
179% [error,Heading,nom_type_read,ext_ima_read,tt,TimeUnit,mode,NbSlice,npx,npy,Calib]=read_imadoc([filebase '.xml']);
180
181%%  mask to reduce the  working area (optional)
182CheckMask=0;
183if isfield(Param,'CheckMask') && isequal(Param.CheckMask,1)
184    [maskname,TestMask]=name_generator([filebase '_1mask'],1,1,'.png','_i');
185        MaskIma=imread(maskname);
186        Mask=MaskIma>=200;%=1 for good points, 0 for bad
187    CheckMask=1;
188end
189%
190% %create dir of the new images
191% [dir_images,namebase]=fileparts(filebase);
192% [path,subdir_ima]=fileparts(dir_images)
193% curdir=pwd;
194% cd(path);
195% mkdir([subdir_ima '_b']);
196% cd(curdir);
197% filebase_b=fullfile(path,[subdir_ima '_b'],namebase);
198
199%
200%
201% lengthtot=siz(1)*siz(2);
202% nbfield=floor(lengthtot/(nbfield2*nbslice_i));%total number of i indexes (adjusted to an integer number of slices)
203% nbfield_slice=nbfield*nbfield2;% number of fields per slice
204% % test_plot=isequal(answer{5},'Yes'); %=1 to display background images
205% if nbaver_ima > nbfield*nbfield2
206%     errordlg('number of images in a slice smaller than the proposed number of images for the sliding average')
207%     return
208% end
209A=[];
210     
211
212% [A,time,dt,rangx0,rangy0]=view_ima(handles,filename,[],1,1,1,1);
213% pxcm=str2num(get(handles.pxcm,'String')); %scales pixels per cm
214% pycm=str2num(get(handles.pycm,'String'));
215% np=size(A);
216
217%BACKGROUND LEVEL
218% Backg=zeros(size(A));
219% nburst(1)=1;
220for ifile=1:nbfield
221    if checkrun
222        if strcmp(get(Param.RUNHandle,'BusyAction'),'queue')
223            update_waitbar(Param.WaitbarHandle,ifile/nbfield)
224        else
225            break% leave the loop if the STOP button is activated on the GUI series
226        end
227    end
228    filename=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,i1_series(ifile),[],j1);
229    A=read_image(filename,FileType,VideoObject,frame_index(ifile));
230    if ndims(A)==3;%color images
231        A=sum(double(Aread),3);% take the sum of color components
232    end
233    if ThreshLum<0
234        A=max(max(A))-A;%take the negative
235    end
236    if TestMask
237        A=A.*Mask;
238    end
239    if isempty(Nblock)
240        A=A-min(min(A));%substract absolute mean
241    else
242        Aflagmin=sparse(imregionalmin(A));%Amin=1 for local image minima
243        Amin=A.*Aflagmin;%values of A at local minima
244        % local background: find all the local minima in image subblocks
245        sumblock= inline('sum(sum(x(:)))');
246        Backgi=blkproc(Amin,[Nblock Nblock],sumblock);% take the sum in  blocks
247        Bmin=blkproc(Aflagmin,[Nblock Nblock],sumblock);% find the number of minima in blocks
248        Backgi=Backgi./Bmin; % find the average of minima in blocks
249        % Backg=Backg+Backgi;
250        Backg=Backgi;
251        A=A-imresize(Backg/nburst(1),size(A),'bilinear');% interpolate to the initial size image and substract
252    end
253    Aflagmax=sparse(imregionalmax(Ap));%find local maxima
254    Plum=imfilter(Ap,hh);% sum A on 5x% domains
255    Plum=Aflagmax.*Plum;% Plum gives the particle luminosity at each particle location, 0 elsewhere
256    %make statistics on particles,restricted to a subdomain Sub
257    [Js,Is,lum]=find(Plum);%particle luminosity
258    Plum=(Plum>ThreshLum).*Plum;% introduce a threshold for particle luminosity
259    Aflagmax=Aflagmax.*(Plum>ThreshLum);
260    [Js,Is,lum]=find(Plum);%particle luminosity
261    nbtotal=size(Is)
262    nbtotal=nbtotal(1);
263    %particle size
264    Parea=Aflagmax.*(Plum./Ap); %particle luminosity/max luminosity=area
265    Pdiam=sqrt(Parea);
266    [Js,Is,diam]=find(Pdiam);%particle location
267   
268    %%%%%%%%%%%%%%%%%%%%%
269   
270    %nbre of particles per block
271%     nbpart=blkproc(Aflagmax,[Nblock Nblock],sumblock);%
272%     npb=size(nbpart);
273%     rangxb=[0.5 (npb(2)-0.5)]*Nblock; % pixel x coordinates for image display
274%     rangyb=[(npb(1)-0.5) 0.5]*Nblock; % pixel y coordinates for image display
275%     image(rangxb,rangyb,nbpart);
276   
277    % get the particle centre of mass
278    dx=imfilter(Ap,hdX);
279    dy=imfilter(Ap,-hdY);
280    dx=Aflagmax.*(dx./Plum);
281    dy=Aflagmax.*(dy./Plum);
282    dx=dx/pxcm;
283    dy=dy/pycm;
284    I=([1:npxy(2)]-0.5)/pxcm; %x pos
285    J=([npxy(1):-1:1]-0.5)/pycm; %y pos
286    [Ipos,Jpos]=meshgrid(I,J);
287    Ipos=reshape(Ipos,1,npxy(2)*npxy(1));
288    Jpos=reshape(Jpos,1,npxy(2)*npxy(1));
289    dx=reshape(dx,1,npxy(2)*npxy(1));
290    dy=reshape(dy,1,npxy(2)*npxy(1));
291    Aflag=reshape(Aflagmax,1,npxy(2)*npxy(1));
292    ind=find(Aflag);% select particle positions
293    XPart{ifile}=Ipos(ind)+dx(ind);
294    YPart{ifile}=Jpos(ind)+dy(ind);     
295end
296hold off
297
298size(XPart{1})
299
300%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301%Trajectoires
302%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303for ifile=1:nbfield
304   
305    [XPart{ifile},YPart{ifile}]=phys_XYZ(Calib,XPart{ifile},YPart{ifile});
306
307end
308
309if nbfield>2
310    figpart=figure
311    hold on
312    plot(XPart{1}(:),YPart{1}(:),'r+')
313    plot(XPart{2}(:),YPart{2}(:),'b+')
314    plot(XPart{3}(:),YPart{3}(:),'y+')
315    legend('particules image 1','particules image 2','particules image 3');
316    xlabel('x (cm)');
317    ylabel('y (cm)');
318    title('Position des particules')
319else
320   figpart=figure
321    hold on
322    plot(XPart{1}(:),YPart{1}(:),'r+')
323    plot(XPart{2}(:),YPart{2}(:),'b+')
324    legend('particules image 1','particules image 2');
325    xlabel('x (cm)');
326    ylabel('y (cm)');
327    title('Position des particules')
328end   
329
330%     prompt={'Ymin (cm)','Ymax( cm)','Xmin (cm)','Xmax (cm)'};
331%     Rep=inputdlg(prompt,'Experiment');
332%     Ymin=str2double(Rep(1));
333%     Ymax=str2double(Rep(2));
334%     Xmin=str2double(Rep(3));
335%     Xmax=str2double(Rep(4));
336   
337    Ymin=6;
338    Ymax=14;
339    Xmin=15;
340    Xmax=35;
341   
342    plot(Xmin,Ymin,'g+')
343    plot(Xmin,Ymax,'g+')
344    plot(Xmax,Ymin,'g+')
345    plot(Xmax,Ymax,'g+')
346
347   
348 for ima=2:nbfield   
349    t{1}=0*ones(size(XPart{1},2),1);
350    burst(1)=0;
351    burst(2)=0.018;
352    burst(3)=0.036;
353%     nburst=strcat('burst',num2str(ima-1),'-',num2str(ima),' (s)');
354%     prompt={'burst (s)'};
355%     Rep=inputdlg(prompt,nburst);
356%     burst(ima)=str2double(Rep(1));
357    t{ima}=(burst(ima)+burst(ima-1))*ones(size(XPart{ima},2),1);
358 end
359
360
361 
362 for ima=1:nbfield
363
364    IndY{ima}=find(YPart{ima}>Ymin & YPart{ima}<Ymax & XPart{ima}>Xmin & XPart{ima}<Xmax);
365    XPart{ima}=XPart{ima}(IndY{ima});
366    YPart{ima}=YPart{ima}(IndY{ima});
367   
368       
369end
370
371
372
373%%%%%%%%%%%%%%%%%%%%%%%
374% Calcul de v1
375%%%%%%%%%%%%%%%%%%%%%%%
376
377for i=1:size(XPart{1},2)
378    MatPos{1}(i,1)=XPart{1}(i);
379    MatPos{1}(i,2)=YPart{1}(i);
380    MatPos{1}(i,3)=t{1}(i);
381    %MatPos{1}(i,4)=i;
382end
383
384for j=1:size(XPart{2},2)-1
385    MatPos{1}(j+size(XPart{1},2),1)=XPart{2}(j);
386    MatPos{1}(j+size(XPart{1},2),2)=YPart{2}(j);
387    MatPos{1}(j+size(XPart{1},2),3)=t{2}(j);
388    %MatPos{1}(j,4)=j+size(XPart{1},2);
389end
390 
391% Dmax=inputdlg('Entrer la distance maximum (0.25 cm)','dmax (cm)',1)
392% dmax=str2num(Dmax{1});
393dmax=0.23;
394
395result{1}=track(MatPos{1},dmax);
396
397izero=1;
398for itest=1:1:size(result{1},1)-1
399    if  result{1}(itest+1,4)==result{1}(itest,4)
400        vitu{1}(izero,1)=(result{1}(itest+1,1)-result{1}(itest,1))/burst(2);
401        vitu{1}(izero,2)=result{1}(itest,4);
402        vitv{1}(izero,1)=(result{1}(itest+1,2)-result{1}(itest,2))/burst(2);
403        vitv{1}(izero,2)=result{1}(itest,4);
404        MatPos{2}(izero,1)=result{1}(itest,1);
405        MatPos{2}(izero,2)=result{1}(itest,2);
406        izero=izero+1;
407    end
408end
409
410
411vitfu{1}=vitu{1};
412vitfv{1}=vitv{1};
413
414
415%%%%%%%%%%%%%%%%%%%%%%%
416% Calcul de vi
417%%%%%%%%%%%%%%%%%%%%%%%
418
419
420if nbfield>2
421    for ima=2:nbfield-1
422       
423       for i=1:size(MatPos{ima},1)
424        MatPos{ima+1}(i,1)=MatPos{ima}(i,1)+(burst(ima+1)*vitfu{ima-1}(i));
425        MatPos{ima+1}(i,2)=MatPos{ima}(i,2)+(burst(ima+1)*vitfv{ima-1}(i));
426        MatPos{ima+1}(i,3)=t{ima}(i);
427      end
428
429      for j=1:size(XPart{ima+1},2)-1
430          MatPos{ima+1}(j+size(MatPos{ima},1),1)=XPart{ima+1}(j);
431          MatPos{ima+1}(j+size(MatPos{ima},1),2)=YPart{ima+1}(j);
432          MatPos{ima+1}(j+size(MatPos{ima},1),3)=t{ima+1}(j);
433      end
434       
435     
436    result{ima}=track(MatPos{ima+1},0.15);
437       
438        izero=1;
439        for itest=1:1:size(result{ima},1)-1
440            if  result{ima}(itest+1,4)==result{ima}(itest,4)
441                vitu{ima}(izero,1)=(result{ima}(itest+1,1)-result{ima}(itest,1))/burst(ima+1);
442                vitu{ima}(izero,2)=result{ima}(itest,4);
443                vitv{ima}(izero,1)=(result{ima}(itest+1,2)-result{ima}(itest,2))/burst(ima+1);
444                vitv{ima}(izero,2)=result{ima}(itest,4);
445                MatPos{ima+2}(izero,1)=result{ima}(itest,1);
446                MatPos{ima+2}(izero,2)=result{ima}(itest,2);
447                izero=izero+1;
448            end   
449        end
450
451            i=vitu{ima}(1,2):1:vitu{ima}(end,2)
452           
453              vitfu{ima}(:,1)=vitfu{ima-1}(i,1)+vitu{ima}(:,1);
454              vitfv{ima}(:,1)=vitfv{ima-1}(i,1)+vitv{ima}(:,1);
455              vitfu{ima}(:,2)=vitu{ima}(:,2);
456              vitfv{ima}(:,2)=vitv{ima}(:,2);
457
458            vitfu{ima-1}=vitfu{ima-1}(i,1);
459            vitfu{ima-1}(:,2)=i;
460            vitfv{ima-1}=vitfv{ima-1}(i,1);
461            vitfv{ima-1}(:,2)=i;
462            i=1:1:size(vitfu{ima-1},1)
463            xpos=MatPos{2}(i,1)
464            ypos=MatPos{2}(i,2)
465      end
466    end
467
468
469
470    figure
471    hold on
472    plot(MatPos{1}(:,1),MatPos{1}(:,2),'r+')
473    plot(MatPos{2}(:,1),MatPos{2}(:,2),'b+')
474    plot(MatPos{4}(:,1),MatPos{4}(:,2),'y+')
475    quiver(xpos(:),ypos(:),vitfu{1}(:,1),vitfv{1}(:,1),'g')
476    quiver(MatPos{4}(:,1),MatPos{4}(:,2),vitfu{2}(:,1),vitfv{2}(:,1),'k')
477    legend('particules image 1','particules image 2', 'particules image 3','vitesse 1-2 (cm/s)','vitesse 2-3 (cm/s)');
478    xlabel('x (cm)');
479    ylabel('y (cm)');
480    title('Position et vitesse (cm/s) des particules')
481   
482
483    for i=1:size(vitfu{end},1)
484     vitfuadd(i)=0;
485     vitfvadd(i)=0;
486    end
487
488   
489   
490         for i=1:1:size(vitfu{end}(:,1))
491           
492                for j=1:nbfield-1
493                    vitfuadd(i)= vitfuadd(i)+vitfu{j}(i,1);
494                    vitfvadd(i)= vitfvadd(i)+vitfv{j}(i,1);
495                    xpos1(i)=MatPos{1}(i,1);
496                    ypos1(i)=MatPos{1}(i,2);
497                    xpos2(i)=MatPos{2}(i,1);
498                    ypos2(i)=MatPos{2}(i,2);
499                   
500                end
501            end
502            sizexpos1=size(xpos1)
503
504    vitfumoy=vitfuadd./(nbfield-1)
505    vitfvmoy=vitfvadd./(nbfield-1)
506
507    testresult1=result{1}
508    testresult2=result{2}
509   
510if nbfield>2   
511    figure
512    hold on
513    plot(MatPos{1}(:,1),MatPos{1}(:,2),'r+')
514    plot(MatPos{2}(:,1),MatPos{2}(:,2),'b+')
515    quiver(xpos2(:),ypos2(:),vitfumoy(:),vitfvmoy(:),'g')
516    legend('particules image 1','particules image 2', 'vitesse moyenne (cm/s)');
517    xlabel('x (cm)');
518    ylabel('y (cm)');
519    title('Position et vitesse (cm/s) des particules')
520   
521else
522
523    figure
524    hold on
525    plot(MatPos{1}(:,1),MatPos{1}(:,2),'r+')
526    plot(MatPos{2}(:,1),MatPos{2}(:,2),'b+')
527    quiver(MatPos{2}(:,1),MatPos{2}(:,2),vitfu{1}(:),vitfv{1}(:),'g')
528    legend('particules image 1','particules image 2','vitesse 1-2 (cm/s)');
529    xlabel('x (cm)');
530    ylabel('y (cm)');
531    title('Position et vitesse (cm/s) des particules')
532   
533    vitfumoy=vitfu{1};
534    vitfvmoy=vitfv{1};
535
536end
537
538VitData.NbDim=2;
539VitData.NbCoord=2;
540VitData.CoordType='phys';
541VitData.dt=0.0185;
542VitData.CoordUnit='cm';
543VitData.Z=0;
544VitData.ListDimName={'nb_vectors'};
545VitData.DimValue=size(vitfumoy,2);
546VitData.ListVarName={'X'  'Y'  'U'  'V'  'F'};
547VitData.VarDimIndex={[1]  [1]  [1]  [1]  [1]};
548VitData.ListVarAttribute={'Role'};
549VitData.Role={'coord_x'  'coord_y'  'vector_x'  'vector_y'  'warnflag'};
550
551if nbfield>2
552    VitData.X=size(MatPos{4},1);
553    VitData.Y=size(MatPos{4},2);
554else
555    VitData.X=size(MatPos{2},1);
556    VitData.Y=size(MatPos{2},2);
557end
558
559VitData.U=size(vitfumoy,2);
560VitData.V=size(vitfvmoy,2);
561VitData.Style='plane';
562VitData.Time=[198.5203 198.5203];
563VitData.Action=Series.Action;
564
565if nbfield>2
566    VitData.X=MatPos{4}(:,1)';
567    VitData.Y=MatPos{4}(:,2)';
568else
569    VitData.X=MatPos{2}(:,1)';
570    VitData.Y=MatPos{2}(:,2)';
571end
572
573VitData.U=vitfumoy(:)';
574VitData.V=vitfvmoy(:)';
575
576if length(VitData.ListVarName) >= 4 & isequal(VitData.ListVarName(1:4), {'X'  'Y'  'U'  'V'})
577       VitData.ListAttribute={'nb_coord','nb_dim','dt','pixcmx','pixcmy','hart','civ','fix'};
578       VitData.nb_coord=2;
579       VitData.nb_dim=2;
580       VitData.dt=0.018;
581       VitData.absolut_time_T0=0;
582       VitData.pixcmx=1; %pix per cm (1 by default)
583       VitData.pixcmy=1; %pix per cm (1 by default)
584       VitData.hart=0;
585           if isequal(VitData.CoordType,'px')
586             VitData.civ=1;
587           else
588             VitData.civ=0;
589           end
590        VitData.fix=0;
591        VitData.ListVarName(1:4)={'vec_X'  'vec_Y'  'vec_U'  'vec_V'};
592        VitData.vec_X=VitData.X;
593        VitData.vec_Y=VitData.Y;
594        VitData.vec_U=VitData.U;
595        VitData.vec_V=VitData.V;
596end
597currentdir=pwd;%store the current working directory
598[Path_ima,Name]=fileparts(filebase);%Path of the image files (.civ)
599cd(Path_ima);%move to the directory of the images: needed to create the result dir by 'mkdir'
600dircur=pwd; %current working directory
601[m1,m2,m3]=mkdir('TRACK_test')
602cd(currentdir)
603[filename_nc,idetect]=name_generator(filebase,num_i1(1),num_j1(1),'.nc','_i_j1-j2',1,num_i1(1),num_j1(2),'TRACK_test')
604error=struct2nc(filename_nc,VitData); %save result file
605if isequal(error,0)
606    [filename_nc ' written']
607else
608    warndlg_uvmat(error,'ERROR')
609end
610
Note: See TracBrowser for help on using the repository browser.