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
 if imgs.animate_reconstructions.frame_rate = 5 (images / sec)
   default value is 5

 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 % if imgs.animate_reconstructions.frame_rate = 5 (images / sec)
0015 %   default value is 5
0016 %
0017 % OUTPUT: fname_out
0018 %     Name of animated file written to.
0019 %     An animated window will not pop up if output requested
0020 
0021 % (C) 2006 Andy Adler. Licensed under GPL version 2 or 3
0022 % $Id: animate_reconstructions.m 6445 2022-12-02 12:07:52Z aadler $
0023 
0024 mk_movie2(fname,imgs)
0025 
0026 if nargout>0
0027    fname_out= [fname, '.gif'];
0028 else
0029    fid= fopen([fname ,'.html'],'w');
0030    fprintf(fid,'<HTML><HEAD><TITLE>%s</TITLE><BODY>\n',fname);
0031    fprintf(fid,'<img src="%s.gif" width="256"></BODY></HTML>',fname);
0032    fclose(fid);
0033    if  ispc %strfind(system_dependent('getos'),'Windows')
0034       system(sprintf('explorer "%s.html"',fname));
0035    else % we hope this is here - under linux etc
0036       system(sprintf('firefox "./%s.html" &',fname));
0037    end
0038 end
0039 
0040 % create avi movie fname
0041 % imds is array of eidors images
0042 %
0043 % This results in really poor images with lots
0044 %  of compression artefacts. NO really good reason to use
0045 function mk_movie(fname, imgs, clim, ref_lev)
0046    fig=figure;
0047    set(fig,'DoubleBuffer','on');
0048    mov = avifile( [fname ,'.avi'] );%, 'Compression', 'RLE' );
0049 
0050    for i=1:length(imgs)
0051      show_slices(imgs(i),1,clim,ref_lev);
0052      F = getframe(gca);
0053      mov = addframe(mov,F);
0054    end
0055    mov = close(mov);
0056    close(fig);
0057 
0058 % create gif movie fname
0059 % imgs is array of eidors images
0060 %
0061 % This requires imagemagick convert program.
0062 function mk_movie2(fname, imgs);
0063    calc_colours('mapped_colour', 127);
0064    dirname= 'tmp_mk_movie2';
0065    rm_rf( dirname );
0066    mkdir( dirname );
0067 
0068    try
0069      show_times = imgs.animate_reconstructions.show_times;
0070    catch 
0071      show_times = 0;
0072    end
0073 
0074    try
0075      frame_rate = imgs.animate_reconstructions.frame_rate;
0076    catch 
0077      frame_rate = 5;
0078    end
0079 
0080    try 
0081      make_avi = imgs.animate_reconstructions.make_avi;
0082    catch 
0083      make_avi = 0;
0084    end
0085 
0086    if make_avi == 1; itp = 'jpg';
0087    else              itp = 'png';
0088    end
0089 
0090    r_img= calc_slices(imgs);
0091    c_img = calc_colours( r_img, imgs);
0092    out_img= reshape(c_img, size(r_img,1), size(r_img,2) ,[]);
0093    cmap= colormap;
0094 
0095    [len_vi, len_hi, len_oi] = size(out_img);
0096 
0097    for i=1:len_oi
0098      this_img  = out_img(:,:,i);
0099      if show_times % add scrollbar on bottom
0100         add_bar = mk_add_bar( (i-1)/(len_oi-1), len_hi );
0101         this_img= [this_img; add_bar];
0102      end
0103      this_name = sprintf('%s/img%06d.%s',dirname, i, itp);
0104      imwrite(this_img, cmap, this_name, itp);
0105    end
0106 
0107    if 0 % enumerate each file
0108       files= dir(sprintf('%s/img*.%s', dirname,itp ));
0109       % font selected is a windows font - how to make os-neutral?
0110       for ff= files(:)'
0111          fn= [dirname,'/',ff.name];
0112          fno= ff.name(4:8);
0113          retval= system_cmd(sprintf( ...
0114           'convert -font 6x8 -draw "text 0,10 ''%s''" %s %s', ...
0115           fno, fn, fn ));
0116       end
0117 
0118    end
0119       
0120    if make_avi == 0
0121       retval= system_cmd(sprintf( ...
0122           'convert -delay %d %s/img*.png -loop 0 %s.gif', ...
0123           frame_rate, dirname, fname ));
0124    else
0125       retval= system_cmd(sprintf( ...
0126           'ffmpeg -r 25 -i %s/img*.jpg -vcodec msmpeg4v2 -y -an -qscale 2 %s.avi', ...
0127           dirname, fname ));
0128    end
0129 
0130    if retval~=0
0131        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');
0132    end
0133    rm_rf(dirname);
0134    if make_avi == 0
0135    fprintf('file %s.gif created (in current directory)\n',fname);
0136    else
0137    fprintf('file %s.avi created (in current directory)\n',fname);
0138    end
0139 
0140 function rm_rf(dirname)
0141    if isdir(dirname)==0
0142        return
0143    end
0144 
0145    if isunix
0146        system(['rm -rf "',dirname,'"']);
0147    else
0148        system(['rmdir /s /q "',dirname,'"']);
0149    end
0150 
0151 function add_bar = mk_add_bar(frac, len) 
0152    sz_bar = 3/len;
0153    ind_val = 90;
0154    xax= linspace(0,1,len) - frac;
0155    yax= 1-abs( xax/sz_bar);
0156    yax= yax.*(yax>0);
0157 
0158    add_bar = round(ind_val * yax);

Generated on Fri 30-Dec-2022 19:44:54 by m2html © 2005