0001 function fname_out= animate_reconstructions(fname, imgs);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
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
0034 system(sprintf('explorer "%s.html"',fname));
0035 else
0036 system(sprintf('firefox "./%s.html" &',fname));
0037 end
0038 end
0039
0040
0041
0042
0043
0044
0045 function mk_movie(fname, imgs, clim, ref_lev)
0046 fig=figure;
0047 set(fig,'DoubleBuffer','on');
0048 mov = avifile( [fname ,'.avi'] );
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
0059
0060
0061
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
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
0108 files= dir(sprintf('%s/img*.%s', dirname,itp ));
0109
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);