【发布时间】:2015-01-08 17:02:01
【问题描述】:
如何在matlab中从一组'.jpg'图像(比如:I1.jpg、I2.jpg、...、I10.jpg)制作'.gif'图像?
【问题讨论】:
-
你的意思是如何使用带有 .gif 扩展名的 imwrite?
-
是的,实际上我浏览了 matlab 教程并尝试将该示例更改为我的情况,但不能因为该示例使用函数绘图,但在我的情况下,它是 jpg 图像。
如何在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”时,它确实是一个不错的动画!
希望有帮助!
【讨论】: