1 | % 'avi2png': copy an avi movie to a series of B/W .png images (take the average of green and blue color components)
|
---|
2 | %----------------------------------------------------------------------
|
---|
3 | function GUI_input=avi2png(num_i1,num_i2,num_j1,num_j2,Series)
|
---|
4 |
|
---|
5 | if ~exist('num_i1','var')
|
---|
6 | GUI_input={};
|
---|
7 | return
|
---|
8 | end
|
---|
9 | hh=guidata(Series.hseries);
|
---|
10 | increment=4;
|
---|
11 | set(hh.incr_i,'String',num2str(increment))
|
---|
12 | nbfield=length(num_i1);
|
---|
13 | % basename=[fullfile(Series.RootPath,Series.RootFile) ];
|
---|
14 | aviname=fullfile(Series.RootPath,[Series.RootFile Series.FileExt]);
|
---|
15 | rootname=fullfile(Series.RootPath,Series.RootFile);
|
---|
16 | if ~exist(rootname,'dir')
|
---|
17 | mkdir(rootname)% will put the extracted images in a subdirectory with the same lname as the avi file (without extension)
|
---|
18 | end
|
---|
19 | basename=fullfile(rootname,'frame');
|
---|
20 |
|
---|
21 | %enable waitbar and stop buttons on the series interface:
|
---|
22 | hRUN=findobj(Series.hseries,'Tag','RUN');% handle of the RUN button
|
---|
23 | hwaitbar=findobj(Series.hseries,'Tag','waitbar');%handle of the waitbar
|
---|
24 | waitbarpos(1)=Series.WaitbarPos(1);%x position of the waitbar
|
---|
25 | waitbarpos(3)=Series.WaitbarPos(3);% width of the waitbar
|
---|
26 |
|
---|
27 | if isequal(lower(Series.FileExt),'.avi')
|
---|
28 | hhh=which('mmreader');%look for the existence of 'mmreader'for movie reading
|
---|
29 | if ~isequal(hhh,'')&& mmreader.isPlatformSupported()
|
---|
30 | MovieObject=mmreader(aviname);
|
---|
31 | FileType='movie';
|
---|
32 | else
|
---|
33 | FileType='avi';
|
---|
34 | end
|
---|
35 | end
|
---|
36 | %main loop
|
---|
37 | for ifile=1:nbfield
|
---|
38 | stopstate=get(hRUN,'BusyAction');
|
---|
39 | if isequal(stopstate,'queue')% if STOP command is not activated
|
---|
40 | waitbarpos(4)=(ifile/nbfield)*Series.WaitbarPos(4);
|
---|
41 | waitbarpos(2)=Series.WaitbarPos(4)+Series.WaitbarPos(2)-waitbarpos(4);
|
---|
42 | set(hwaitbar,'Position',waitbarpos)%update waitbar on the series interface
|
---|
43 | drawnow
|
---|
44 | D=read_image(aviname,'movie',num_i1(ifile),MovieObject);
|
---|
45 | C=uint8(D);% transform to 8 bit integers
|
---|
46 | new_index=1+floor((num_i1(ifile)-num_i1(1))/increment);
|
---|
47 | filename=[basename '_' num2str(new_index) '.png'];%create image name
|
---|
48 | imwrite(C,filename,'BitDepth',8);%write image
|
---|
49 | end
|
---|
50 | end
|
---|
51 |
|
---|
52 | %create xml file with timing:
|
---|
53 | info=aviinfo(aviname);
|
---|
54 | t=xmltree;
|
---|
55 | t=set(t,1,'name','ImaDoc');
|
---|
56 | [t,uid]=add(t,1,'element','Heading');
|
---|
57 | % A AJOUTER
|
---|
58 | % Heading.Project='';
|
---|
59 | Heading.ImageName=[Series.RootFile '_' num2str(num_i1(1)) '.png'];
|
---|
60 | t=struct2xml(Heading,t,uid);
|
---|
61 | [t,uid]=add(t,1,'element','Camera');
|
---|
62 | Camera.TimeUnit='s';
|
---|
63 | Camera.BurstTiming.FrameFrequency=info.FramesPerSecond/increment;
|
---|
64 | Camera.BurstTiming.Dti=1;
|
---|
65 | Camera.BurstTiming.NbDti=numel(num_i1)-1;
|
---|
66 | Camera.BurstTiming.Time=(num_i1(1)-1)/info.FramesPerSecond;%time of the first frame of the avi movie
|
---|
67 | t=struct2xml(Camera,t,uid);
|
---|
68 | save(t,[basename '.xml'])
|
---|
69 |
|
---|
70 | %------------------------------------------------------------------------
|
---|
71 | %--read images and convert them to the uint16 format used for PIV
|
---|
72 | function A=read_image(filename,type_ima,num,MovieObject)
|
---|
73 | %------------------------------------------------------------------------
|
---|
74 | %num is the view number needed for an avi movie
|
---|
75 | switch type_ima
|
---|
76 | case 'movie'
|
---|
77 | A=read(MovieObject,num);
|
---|
78 | case 'avi'
|
---|
79 | mov=aviread(filename,num);
|
---|
80 | A=frame2im(mov(1));
|
---|
81 | case 'multimage'
|
---|
82 | A=imread(filename,num);
|
---|
83 | case 'image'
|
---|
84 | A=imread(filename);
|
---|
85 | end
|
---|
86 | siz=size(A);
|
---|
87 | if length(siz)==3;%color images
|
---|
88 | A=sum(double(A(:,:,2:3)),3)/2;% average green and blue components
|
---|
89 | end
|
---|