如何在Matlab中从一组``.jpg''图像(例如:I1.jpg,I2.jpg,...,I10.jpg)制作``.gif''图像?
好的,这是一个简单的示例。我得到了一个带有独角兽的图像,并删除了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”时,它确实是一个不错的动画!
希望对您有所帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句