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 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
0031 system(sprintf('firefox "./%s.html" &',fname));
0032 end
0033 end
0034
0035
0036
0037
0038
0039
0040 function mk_movie(fname, imgs, clim, ref_lev)
0041 fig=figure;
0042 set(fig,'DoubleBuffer','on');
0043 mov = avifile( [fname ,'.avi'] );
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
0054
0055
0056
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
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
0099 files= dir(sprintf('%s/img*.%s', dirname,itp ));
0100
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
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
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);