Reputation: 181
I am writing a simple code to convert a tiff stack to a .avi movie. Here is my current code
TiffName='Un102319_1466ul_min_3.tif';
filename='movieTest';
for i=1:numel(imfinfo(TiffName))
imshow(imread(TiffName,i))
mov(i)=getframe(gca);
end
movie2avi(mov, filename);
The imshow() works fine, but the movie shows only the toolbar above the image. It seems that getframe isn't doing what I thought it was supposed to do.
Upvotes: 2
Views: 1979
Reputation: 104484
The code you wrote works for me. My suspicion is your getframe
call is wrong. Simply call it without gca
. You want the current figure, not the current axes.
As such:
TiffName = 'Un102319_1466ul_min_3.tif';
filename='movieTest';
in = imfinfo(TiffName);
for k = 1 : numel(in)
imshow(imread(TiffName, k));
mov(k) = getframe; %// Change here
end
movie2avi(mov, filename);
This will give you what you want, but movie2avi
doesn't offer a lot of choices in terms of compression algorithms. As such, I would recommend you go with the VideoWriter
approach and take a look at Benoit_11's answer.
Good luck!
Upvotes: 1
Reputation: 13945
Maybe use a videowriter object:
mov((1:nFrames) = struct('cdata', [], 'colormap',[]);
YourVideo = VideoWriter('MovieName.avi'); % you can add compression options also
YourVideo.FrameRate = 15; % Select frame rate
open(YourVideo);
for k = 1:nFrames
mov(k).cdata = getframe(gca);
writeVideo(YourVideo,mov(k).cdata);
end
close(YourVideo);
Upvotes: 1