animate_reconstructions

PURPOSE ^

animate_reconstructions(fname, imgs);

SYNOPSIS ^

function fname_out= animate_reconstructions(fname, imgs);

DESCRIPTION ^

 animate_reconstructions(fname, imgs);
 animate a sequence of reconstructed images

 PARAMETER:  fname
     filename to save to (extension is added)
 PARAMETER:  imgs
     is array of eidors images

 if imgs.animate_reconstructions.show_times = 1
   then a timescale is shown on the bottom
 if imgs.animate_reconstructions.make_avi = 1
   then use ffmpeg to write an avi

 OUTPUT: fname_out
     Name of animated file written to.
     An animated window will not pop up if output requested

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function fname_out= animate_reconstructions(fname, imgs);
0002 % animate_reconstructions(fname, imgs);
0003 % animate a sequence of reconstructed images
0004 %
0005 % PARAMETER:  fname
0006 %     filename to save to (extension is added)
0007 % PARAMETER:  imgs
0008 %     is array of eidors images
0009 %
0010 % if imgs.animate_reconstructions.show_times = 1
0011 %   then a timescale is shown on the bottom
0012 % if imgs.animate_reconstructions.make_avi = 1
0013 %   then use ffmpeg to write an avi
0014 %
0015 % OUTPUT: fname_out
0016 %     Name of animated file written to.
0017 %     An animated window will not pop up if output requested
0018 
0019 mk_movie2(fname,imgs)
0020 
0021 if nargout>0
0022    fname_out= [fname, '.gif'];
0023 else
0024    fid= fopen([fname ,'.html'],'w');
0025    fprintf(fid,'<HTML><HEAD><TITLE>%s</TITLE><BODY>\n',fname);
0026    fprintf(fid,'<img src="%s.gif" width="256"></BODY></HTML>',fname);
0027    fclose(fid);
0028    if  strfind(system_dependent('getos'),'Windows')
0029       system(sprintf('explorer "%s.html"',fname));
0030    else % we hope this is here - under linux etc
0031       system(sprintf('firefox "./%s.html" &',fname));
0032    end
0033 end
0034 
0035 % create avi movie fname
0036 % imds is array of eidors images
0037 %
0038 % This results in really poor images with lots
0039 %  of compression artefacts. NO really good reason to use
0040 function mk_movie(fname, imgs, clim, ref_lev)
0041    fig=figure;
0042    set(fig,'DoubleBuffer','on');
0043    mov = avifile( [fname ,'.avi'] );%, 'Compression', 'RLE' );
0044 
0045    for i=1:length(imgs)
0046      show_slices(imgs(i),1,clim,ref_lev);
0047      F = getframe(gca);
0048      mov = addframe(mov,F);
0049    end
0050    mov = close(mov);
0051    close(fig);
0052 
0053 % create gif movie fname
0054 % imgs is array of eidors images
0055 %
0056 % This requires imagemagick convert program.
0057 function mk_movie2(fname, imgs);
0058    calc_colours('mapped_colour', 127);
0059    dirname= 'tmp_mk_movie2';
0060    rm_rf( dirname );
0061    mkdir( dirname );
0062 
0063    try
0064      show_times = imgs.animate_reconstructions.show_times;
0065    catch 
0066      show_times = 0;
0067    end
0068 
0069    try 
0070      make_avi = imgs.animate_reconstructions.make_avi;
0071    catch 
0072      make_avi = 0;
0073    end
0074 
0075    if make_avi == 1; itp = 'jpg';
0076    else              itp = 'png';
0077    end
0078 
0079    r_img= calc_slices(imgs);
0080    c_img = calc_colours( r_img, imgs);
0081    out_img= reshape(c_img, size(r_img,1), size(r_img,2) ,[]);
0082    cmap= colormap;
0083 
0084    [len_vi, len_hi, len_oi] = size(out_img);
0085 
0086    for i=1:len_oi
0087      this_img  = out_img(:,:,i);
0088      if show_times % add scrollbar on bottom
0089         add_bar = mk_add_bar( (i-1)/(len_oi-1), len_hi );
0090         this_img= [this_img; add_bar];
0091      end
0092      this_name = sprintf('%s/img%06d.%s',dirname, i, itp);
0093      imwrite(this_img, cmap, this_name, itp);
0094    end
0095 
0096    ld_lib_path= sys_dep;
0097 
0098    if 0 % enumerate each file
0099       files= dir(sprintf('%s/img*.%s', dirname,itp ));
0100       % font selected is a windows font - how to make os-neutral?
0101       for ff= files(:)'
0102          fn= [dirname,'/',ff.name];
0103          fno= ff.name(4:8);
0104          retval= system(sprintf( ...
0105           '%s convert -font 6x8 -draw "text 0,10 ''%s''" %s %s', ...
0106           ld_lib_path, fno, fn, fn ));
0107       end
0108 
0109    end
0110       
0111    if make_avi == 0
0112       retval= system(sprintf( ...
0113           '%s convert -delay 5 %s/img*.png -loop 0 %s.gif', ...
0114           ld_lib_path, dirname, fname ));
0115    else
0116       retval= system(sprintf( ...
0117           '%s ffmpeg -qscale 2 -r 25 -i %s/img*.jpg -vcodec msmpeg4v2 -y -an %s.avi', ...
0118           ld_lib_path, dirname, fname ));
0119    end
0120 
0121    if retval~=0
0122        error('please ensure the imagemagick convert program is in your path. Under windows the easist is to download from www.imagemagick.org/script/binary-releases.php');
0123    end
0124    rm_rf(dirname);
0125    if make_avi == 0
0126    fprintf('file %s.gif created (in current directory)\n',fname);
0127    else
0128    fprintf('file %s.avi created (in current directory)\n',fname);
0129    end
0130 
0131 function rm_rf(dirname)
0132    if isdir(dirname)==0
0133        return
0134    end
0135 
0136    if isunix
0137        system(['rm -rf "',dirname,'"']);
0138    else
0139        system(['rmdir /s /q "',dirname,'"']);
0140    end
0141 
0142 % work around stupid matlab bugs
0143 function ld_lib_path= sys_dep;
0144    ld_lib_path='';
0145    if  strfind(system_dependent('getos'),'Linux')
0146      vv=version; 
0147      ff=find(vv == ' '); 
0148      if length(ff)>0;vv=vv(1:ff(1)-1);end
0149      ff=find(vv == '.');
0150      if length(ff)>1;vv=vv(1:ff(2)-1);end     
0151      if str2num(vv)>=7
0152         %Version 7 under linux sets the LD_LIBRARY_PATH and that breaks external progs
0153           ld_lib_path='LD_LIBRARY_PATH=;';
0154       end      
0155    end    
0156 
0157 function add_bar = mk_add_bar(frac, len) 
0158    sz_bar = 3/len;
0159    ind_val = 90;
0160    xax= linspace(0,1,len) - frac;
0161    yax= 1-abs( xax/sz_bar);
0162    yax= yax.*(yax>0);
0163 
0164    add_bar = round(ind_val * yax);

Generated on Tue 09-Aug-2011 11:38:31 by m2html © 2005