如何在matlab中从一组图像中制作gif图像? [英] How to make gif images from a set of images in matlab?

查看:409
本文介绍了如何在matlab中从一组图像中制作gif图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在matlab中制作一组'.jpg'图像(例如:I1.jpg,I2.jpg,...,I10.jpg)中的'.gif'图像?

How to make '.gif' image from a set of '.jpg' images (say: I1.jpg, I2.jpg,..., I10.jpg) in matlab?

推荐答案

这里有一个简单的例子。我有一个带有独角兽的图像并删除2部分以创建3个不同的图像,只是为了创建一个GIF动画。这是它的样子:

Ok here is a simple example. I got an image with a unicorn on it and remove 2 part to create 3 different images, just for the sake of creating an animated gif. Here is what it looks like:

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'时,它确实是一个很好的动画!

As you see, its not that different from the example on the Mathworks website. Here my images are in a cell array but yours might be in a regular array or something else.That should work fine; when I open 'UnicornAnimation.gif' it is indeed a nice animation!

希望有所帮助!

这篇关于如何在matlab中从一组图像中制作gif图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆