Changeset 176
- Timestamp:
- Jan 7, 2011, 1:50:08 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/series/avi2png.m
r175 r176 2 2 %---------------------------------------------------------------------- 3 3 function GUI_input=avi2png(num_i1,num_i2,num_j1,num_j2,Series) 4 %% INPUT PARAMETERS (to edit) 5 increment=4% frame increment: the frequency of the png images will be (initial frequency)/increment. 6 colorweight=[0 0.5 0.5]; % relative weight of color components [r g b] for the resulting B/W image 7 colorweight=colorweight/sum(colorweight) 4 8 9 %% default output (set the input options in the GUI series) 5 10 if ~exist('num_i1','var') 6 11 GUI_input={}; … … 8 13 end 9 14 hh=guidata(Series.hseries); 10 increment=4; 11 set(hh.incr_i,'String',num2str(increment)) 15 set(hh.incr_i,'String',num2str(increment))% preset the increment in the GUI 16 17 %% set file names 12 18 nbfield=length(num_i1); 13 % basename=[fullfile(Series.RootPath,Series.RootFile) ];14 19 aviname=fullfile(Series.RootPath,[Series.RootFile Series.FileExt]); 15 20 rootname=fullfile(Series.RootPath,Series.RootFile); … … 19 24 basename=fullfile(rootname,'frame'); 20 25 21 % enable waitbar and stop buttons on the series interface:26 %% enable waitbar and stop buttons on the series interface: 22 27 hRUN=findobj(Series.hseries,'Tag','RUN');% handle of the RUN button 23 28 hwaitbar=findobj(Series.hseries,'Tag','waitbar');%handle of the waitbar … … 25 30 waitbarpos(3)=Series.WaitbarPos(3);% width of the waitbar 26 31 32 %% read the movie object 27 33 if isequal(lower(Series.FileExt),'.avi') 34 display('opening the avi movie ...') 28 35 hhh=which('mmreader');%look for the existence of 'mmreader'for movie reading 29 36 if ~isequal(hhh,'')&& mmreader.isPlatformSupported() … … 34 41 end 35 42 end 36 %main loop 43 44 %% main loop on frames 37 45 for ifile=1:nbfield 38 46 stopstate=get(hRUN,'BusyAction'); … … 42 50 set(hwaitbar,'Position',waitbarpos)%update waitbar on the series interface 43 51 drawnow 44 D=read_image(aviname,'movie',num_i1(ifile),MovieObject); 45 C=uint8(D);% transform to 8 bit integers 52 A=read_image(aviname,'movie',num_i1(ifile),MovieObject); 53 if ndims(A)==3% convert color image to B/W 54 A=double(A); 55 A=colorweight(1)*A(:,:,1)+colorweight(2)*A(:,:,2)+colorweight(3)*A(:,:,3); 56 A=uint8(A);% transform to 8 bit integers 57 end 46 58 new_index=1+floor((num_i1(ifile)-num_i1(1))/increment); 47 59 filename=[basename '_' num2str(new_index) '.png'];%create image name 48 imwrite(C,filename,'BitDepth',8);%write image 60 imwrite(A,filename,'BitDepth',8);%write image 61 display(['new frame ' num2str(new_index) ' written as png image']) 49 62 end 50 63 end 51 64 52 % create xml file with timing:65 %% create xml file with timing: 53 66 info=aviinfo(aviname); 54 67 t=xmltree; … … 57 70 % A AJOUTER 58 71 % Heading.Project=''; 59 Heading.ImageName= [Series.RootFile '_' num2str(num_i1(1)) '.png'];72 Heading.ImageName='frame_1.png'; 60 73 t=struct2xml(Heading,t,uid); 61 74 [t,uid]=add(t,1,'element','Camera'); 62 75 Camera.TimeUnit='s'; 63 Camera.BurstTiming.FrameFrequency=info.FramesPerSecond/increment;64 Camera.BurstTiming.Dti= 1;76 % Camera.BurstTiming.FrameFrequency=info.FramesPerSecond/increment; 77 Camera.BurstTiming.Dti=increment/info.FramesPerSecond; 65 78 Camera.BurstTiming.NbDti=numel(num_i1)-1; 66 79 Camera.BurstTiming.Time=(num_i1(1)-1)/info.FramesPerSecond;%time of the first frame of the avi movie … … 84 97 A=imread(filename); 85 98 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 99
Note: See TracChangeset
for help on using the changeset viewer.