Friday, July 10, 2009
on md
Wednesday, July 8, 2009
data files to image to video using Matlab
%usage: datatoimg('dat', '/Users/alex/Documents/MATLAB/files/temp', '*');
%if you find any errors ask me
%Athens: 8-7-09
warning('datatoimg:warning','Do NOT close or open any window during the process!\n')
filearray=dir([imdir filesep '*.' ext])
numfiles=size(filearray,1)
cd (imdir);
for i=1:1:numfiles
[x, y] = textread(filearray(i).name, '%f %f');
currentPlot = plot(x, y);
title(i);
axis([350 800 -50 250])
saveas(currentPlot,[filearray(i).name,'.jpg'],'jpg');
clear currentPlot;
end
im2avi('jpg', '', 1, 1, 'myOutput', 0, filearray);
function varargout=im2avi(ext, imdir, scale, framerate, filename, playflag, directory)
% 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([directory filesep '*.' ext]);
s=size(filearray,1);
frameind=0;
mv =struct('cdata',{}, 'colormap', {});
figure, h =gcf;
for i=1:s
frameind=frameind+1;
imgname=[filearray(i).name];
im=imread(imgname) ;
im=imresize(im, scale);
imshow(im);
mv(frameind)=getframe(h);
end
close(h)
movie2avi(mv, [directory filesep filename '.avi'], 'fps', framerate);
if nargout >0
varargout{1} =mv;
end
if playflag>0
movie(mv, playflag);
end