JPG to GIF animation

조회 수: 18 (최근 30일)
Mathew Smith
Mathew Smith 2022년 9월 12일
댓글: Mathew Smith 2022년 9월 12일
Hi,
I am using this code for conversion of JPGs to GIF animation. It works but produces strange colors (first and second picture in animation have incorrect colors and third is OK).
I would like to ask you to hep with correction of the code.
clear
clc
%// Image source: http:\\giantbomb.com
[A,map] = rgb2ind(imread('obr_0.jpg'),256);
[B,map] = rgb2ind(imread('obr_01.jpg'),256);
[C,map] = rgb2ind(imread('obr_99.jpg'),256);
ImageCell = {A;B;C};
%// Just to show what the images look like (I removed spots to make sure there was an animation created):
%// Create file name.
FileName = 'test.gif';
for k = 1:numel(ImageCell)
if k ==1
%// For 1st image, start the 'LoopCount'.
imwrite(ImageCell{k},map,FileName,'gif','LoopCount',Inf,'DelayTime',1);
else
imwrite(ImageCell{k},map,FileName,'gif','WriteMode','append','DelayTime',1);
end
end
BR
Mathew

채택된 답변

Simon Chan
Simon Chan 2022년 9월 12일
The colormap for the first two figures are overwritten by the third one in the following:
[A,map] = rgb2ind(imread('obr_0.jpg'),256);
[B,map] = rgb2ind(imread('obr_01.jpg'),256); % Overwrite 1st time
[C,map] = rgb2ind(imread('obr_99.jpg'),256); % Overwrite 2nd time
  댓글 수: 2
Mathew Smith
Mathew Smith 2022년 9월 12일
Thank you very much! It is true.
Mathew Smith
Mathew Smith 2022년 9월 12일
Do you have an idea how to store [A,map] in ImageCell so that later it can be used for command "imgwrite" using FOR-END loop?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by