如何制作' .gif'来自一组' .jpg'在matlab中的图像(比如:I1.jpg,I2.jpg,...,I10.jpg)
答案 0 :(得分:4)
好的,这是一个简单的例子。我得到了一张带有独角兽的图像并删除了2部分以创建3个不同的图像,只是为了创建一个GIF动画。这是它的样子:
clear
clc
%// Image source: http:\\giantbomb.com
A = rgb2gray(imread('Unicorn1.jpg'));
B = rgb2gray(imread('Unicorn2.jpg'));
C = rgb2gray(imread('Unicorn3.jpg'));
ImageCell = {A;B;C};
figure;
subplot(131)
imshow(A)
subplot(132)
imshow(B)
subplot(133)
imshow(C)
%// Just to show what the images look like (I removed spots to make sure there was an animation created):
%// Create file name.
FileName = 'UnicornAnimation.gif';
for k = 1:numel(ImageCell)
if k ==1
%// For 1st image, start the 'LoopCount'.
imwrite(ImageCell{k},FileName,'gif','LoopCount',Inf,'DelayTime',1);
else
imwrite(ImageCell{k},FileName,'gif','WriteMode','append','DelayTime',1);
end
end
如您所见,它与Mathworks网站上的示例没有什么不同。这里我的图像是在一个单元格数组中,但你的图像可能是一个常规数组或其他东西。这应该工作正常;当我打开'UnicornAnimation.gif'时,它确实是一个很好的动画!
希望有所帮助!