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

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

+1
source share
1 answer

Ok, here is a simple example. I got an unicorn image and delete 2 parts to create 3 different images, just for the sake of creating an animated gif. Here's 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):

enter image description here

%// 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", !

, !

+3

Source: https://habr.com/ru/post/1536623/


All Articles