MATLAB Answers

0

How to create fade gif image OUT OF 6 IMAGES AS GIVEN IN PICTURE?

Asked by edusadiq on 30 Oct 2019
Latest activity Commented on by darova
on 3 Nov 2019
Can someone illustrate in MATLAB the given effect with complete code?
Convert gradually from first image to last image(total 6 images);

  0 Comments

Sign in to comment.

Products


Release

R2019a

1 Answer

Answer by darova
on 30 Oct 2019
 Accepted Answer

Read about gif animation in help
Here is an idea:
n = 5 % number of changes between images
for i = 1:n
I = (I1*(i-1) + I2*(n-i))/(n-1); % average image
end
% I = (I1*0 + I2*4)/4
% I = (I1*1 + I2*3)/4
% I = (I1*2 + I2*2)/4
% and so on

  4 Comments

Show 1 older comment
Example
clc,clear
filename = 'gif_animation.gif';
I1 = imread('1.png');
[im,map] = rgb2ind(I1,255);
imwrite(im,map,filename,'DelayTime',0,'Loopcount',inf);
n = 10; % number of changes between images
for i = 1:3 % loop through images
I1 = imread( sprintf('%d.png',i) ); % read current image
I2 = imread( sprintf('%d.png',i+1) ); % read next image
I1 = double(I1);
I2 = double(I2);
for j = 1:n % loop through changes
% operations with double numbers
I = (I1*(n-j) + I2*(j-1))/(n-1); % average image
% convert to uint8 again
I = uint8(I);
[im,map] = rgb2ind(I,255);
imwrite(im,map,filename,'DelayTime',0.1,'WriteMode','Append');
end
end
Result:
gif_animation.gif
Images attached
It works 100%.
Thank you darova. You really did it.
I'll be happy if you reply for later questions of mine!
  • I'll be happy if you reply for later questions of mine!
I'll be happy too. Ask!

Sign in to comment.