Changeset 176


Ignore:
Timestamp:
Jan 7, 2011, 1:50:08 AM (10 years ago)
Author:
sommeria
Message:

avi2png cleaned and generalised

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/series/avi2png.m

    r175 r176  
    22%----------------------------------------------------------------------
    33function GUI_input=avi2png(num_i1,num_i2,num_j1,num_j2,Series)
     4%% INPUT PARAMETERS (to edit)
     5increment=4% frame increment: the frequency of the png images will be (initial frequency)/increment.
     6colorweight=[0 0.5 0.5]; % relative weight of color components [r g b] for the resulting B/W image
     7colorweight=colorweight/sum(colorweight)
    48
     9%% default output (set the input options in the GUI series)
    510if ~exist('num_i1','var')
    611    GUI_input={};
     
    813end
    914hh=guidata(Series.hseries);
    10 increment=4;
    11 set(hh.incr_i,'String',num2str(increment))
     15set(hh.incr_i,'String',num2str(increment))% preset the increment in the GUI
     16
     17%% set file names
    1218nbfield=length(num_i1);
    13 % basename=[fullfile(Series.RootPath,Series.RootFile) ];
    1419aviname=fullfile(Series.RootPath,[Series.RootFile Series.FileExt]);
    1520rootname=fullfile(Series.RootPath,Series.RootFile);
     
    1924basename=fullfile(rootname,'frame');
    2025
    21 %enable waitbar and stop buttons on the series interface:
     26%% enable waitbar and stop buttons on the series interface:
    2227hRUN=findobj(Series.hseries,'Tag','RUN');% handle of the RUN button
    2328hwaitbar=findobj(Series.hseries,'Tag','waitbar');%handle of the waitbar
     
    2530waitbarpos(3)=Series.WaitbarPos(3);% width of the waitbar
    2631
     32%% read the movie object
    2733if isequal(lower(Series.FileExt),'.avi')
     34    display('opening the avi movie ...')
    2835    hhh=which('mmreader');%look for the existence of 'mmreader'for movie reading
    2936    if ~isequal(hhh,'')&& mmreader.isPlatformSupported()
     
    3441    end
    3542end
    36 %main loop
     43
     44%% main loop on frames
    3745for ifile=1:nbfield
    3846     stopstate=get(hRUN,'BusyAction');
     
    4250        set(hwaitbar,'Position',waitbarpos)%update waitbar on the series interface
    4351        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
    4658        new_index=1+floor((num_i1(ifile)-num_i1(1))/increment);
    4759        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'])
    4962     end
    5063end
    5164
    52 %create xml file with timing:
     65%% create xml file with timing:
    5366info=aviinfo(aviname);
    5467t=xmltree;
     
    5770% A AJOUTER
    5871% Heading.Project='';
    59 Heading.ImageName=[Series.RootFile '_' num2str(num_i1(1)) '.png'];
     72Heading.ImageName='frame_1.png';
    6073t=struct2xml(Heading,t,uid);
    6174[t,uid]=add(t,1,'element','Camera');
    6275Camera.TimeUnit='s';
    63 Camera.BurstTiming.FrameFrequency=info.FramesPerSecond/increment;
    64 Camera.BurstTiming.Dti=1;
     76% Camera.BurstTiming.FrameFrequency=info.FramesPerSecond/increment;
     77Camera.BurstTiming.Dti=increment/info.FramesPerSecond;
    6578Camera.BurstTiming.NbDti=numel(num_i1)-1;
    6679Camera.BurstTiming.Time=(num_i1(1)-1)/info.FramesPerSecond;%time of the first frame of the avi movie
     
    8497        A=imread(filename);
    8598end
    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.