2007年5月21日星期一

用MATLAB转换图片到avi视频

“im2avi”是一个MATLAB函数,可以转换图片到avi视频,这是一个简化版本。

function varargout=im2avi(ext, imdir, scale, framerate, filename, playflag)
% im2avi converts image sequenses to avi video
%
% SYNTAX
%
% Inputs: imdir: image sequense directory
% ext: the extension name of the image such as 'jpg', 'tif',
% scale: image resize, like [320 400] or 0.9
% framerate: avi video frame rate
% filename: save avi as
% playflag: play the avi video, if it is 0, no play, if >0,
% play the avi 'playflag' times.
%
% EXAMPLE: im2avi(ext, imdir, scale, framerate, filename, playflag)
%
% NOTES: based on im2avi (author: Zhe Wu @ Univ of Rochester)
% Wenbin, 09-May-2007

warning('im2avi:warning','Do NOT close or open any image window during the process!\n')

filearray=dir([imdir filesep '*.' ext]);
s=size(filearray,1);

frameind=0;
mv =struct('cdata',{}, 'colormap', {});
figure, h =gcf;

for i=1:s
frameind=frameind+1;
imgname=[imdir filesep filearray(i).name];
im=imread(imgname) ;
im=imresize(im, scale);
imshow(im);
mv(frameind)=getframe(h);
end
close(h)

movie2avi(mv, [imdir filesep filename '.avi'], 'fps', framerate);

if nargout >0
varargout{1} =mv;
end

if playflag>0
movie(mv, playflag);
end

英文版:

Convert images to avi video in MATLAB

http://nw360.blogspot.com/2007/05/convert-images-to-avi-video.html

1 条评论:

匿名 说...

谢谢呀,如果是图像序列,怎么转换成avi视频,能不能举个例子,或发我信箱里,谢谢lyphy2002@sina.com QQ:552145851