How to make gif images from a set of images in matlab?

元气小坏坏 提交于 2019-12-22 15:01:22

问题


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


回答1:


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

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!

Hope that helps!



来源:https://stackoverflow.com/questions/26876885/how-to-make-gif-images-from-a-set-of-images-in-matlab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!