#!/usr/bin/perl # Creates AVI animation via MATLAB. Supports png, tif, gif, jpg # # rsz 9.24.2004 # rsz 9.27.2004 added fps support # rsz 12.15.2004 added paletted image support use Getopt::Std; getopts("vf:"); if ( ($#ARGV + 1) < 2) { print "\nMakes an AVI movie with MATLAB from an image sequence.\n"; print "\nmkavi.pl [-v] [-f fps] files fileout\n\n"; print "-v Verbose\n"; print "-f Frames per second\n"; print "\nExamples:\n"; print " mkavi.pl img*.png movie.avi\n"; print " mkavi.pl `ls -c1 img*.png | sort -n` movie.avi\n"; exit; } $fileout = $ARGV[$#ARGV]; $filesin = "'$ARGV[0]'"; if ($opt_v) { $verbose = 1; } else { $verbose = 0; } if ($opt_f) { $fps = "$opt_f"; } else { $fps = "6"; } # create list of files that matlab can process for($i=1; $i < $#ARGV; ++$i) { $filesin .= ",'$ARGV[$i]'"; } # create the matlab script $script = <<"EOF"; files = {$filesin}; for i = 1:length(files), if $verbose, disp(['Reading frame ', num2str(i), ' of ', num2str(length(files))]); end [img, cmap] = imread(files{i}); if ndims(img) == 2 % not true color, but indexed like GIF [nr,nc] = size(img); img2 = zeros(nr, nc, 3); img2(:) = cmap(double(img(:))+1, :); img = img2; end M(i) = im2frame(img); end if $verbose, disp('Creating AVI at $fps fps...'); end % note: no compression on unix movie2avi(M, '$fileout', 'fps', $fps, 'keyframe', 1, 'quality', 100); if $verbose, disp('AVI Created'); end exit; EOF $tmp = "tmp$$"; # create the tmp script file `echo "$script" > $tmp.m`; # must call matlab with a filename without any '.' or extension $cmd = "matlab -nosplash -nodesktop -r $tmp"; # run matlab if ($verbose) { print "Starting MATLAB...\n"; system($cmd); } else { `$cmd`; } # clean up `rm $tmp.m`; #====================================================================== # U.S. Department of Commerce (DOC) Software License for script # developed at the Geophysical Fluid Dynamics Laboratory/NOAA. # # 1. Scope of License # # Subject to all the terms and conditions of this license, DOC grants # USER the royalty-free, nonexclusive, nontransferable, and worldwide # rights to reproduce, modify, and distribute this script # developed at the Geophysical Fluid Dynamics Laboratory/NOAA, herein # referred to as the Product. # # 2. Conditions and Limitations of Use # # Warranties. Neither the U.S. Government, nor any agency or # employee thereof, makes any warranties, expressed or implied, # with respect to the Product provided under this License, # including but not limited to the implied warranties or # merchantability and fitness for any particular purpose. # # Liability. In no event shall the U.S. Government, nor any agency # or employee thereof, be liable for any direct, indirect, or # consequential damages flowing from the use of the Product # provided under this License. # # Non-Assignment. Neither this License nor any rights granted # hereunder are transferable or assignable without the explicit # prior written consent of DOC. # # Names and Logos. USER shall not substitute its name or logo for the # name or logo of DOC, or any of its agencies, in identification of # the Product. # # Export of technology. USER shall comply with all U.S. laws and # regulations restricting the export of the Product to other # countries. # # Governing Law. This License shall be governed by the laws of # United States as interpreted and applied by the Federal courts # in the District of Columbia. # # 3. Term of License This License shall remain in effect as long as USER # uses the Product in accordance with Paragraphs 1 and 2. #======================================================================