フィルターのクリア

GIF speed not as expected! Help!

110 ビュー (過去 30 日間)
Valerio Biscione
Valerio Biscione 2015 年 3 月 15 日
コメント済み: DGM 2023 年 4 月 23 日
Hello. I am trying to generate a GIF of a growing bar. However, the speed of the generating gif is really slow, and I don't understand how to make it faster. The 'DelayTime' is set to 0, and when the animation is generated in MATLAB is looks really fine. However, when I open the bar.gif, the animation is not fluid at all. This is the code
%draw rectangle and lambda
clear;
figure();
rectangle('Position',[0 2 10 1]);
axis off
set(gcf,'Position',[ -901 789 579 70])
t=0:0.05:3
l=1; a=0.5
p=@(t,l,a) 1-(1-a).*exp(-l.*t);
x=[0 0 10 10];
y=[2 3 3 2];
patch(x,y,'white');
frame=getframe(gca); im=frame2im(frame);
[imind,cm] = rgb2ind(im,256);
filename='bar.gif';
imwrite(imind,cm,filename,'gif','DelayTime',0.5, 'Loopcount',inf);
for tt=1:length(t)
pt=p(t(tt),l,a);
x=[0 0 10.*pt 10.*pt];
patch(x,y,'green');
% pause(.01); drawnow;
frame(tt)=getframe(gca);
end
for tt=1:length(t)
im=frame2im(frame(tt));
[imind,cm] = rgb2ind(im,256);
imwrite(imind,cm,filename, 'gif','DelayTime',0,'WriteMode','append');
end
  1 件のコメント
John D'Errico
John D'Errico 2017 年 11 月 14 日
編集済み: John D'Errico 2017 年 11 月 14 日
@DA Huang: Please don't answer a question with your own question. Use comments to make a comment.
Moved an answer by Da Huang into a comment:
"Have you solve this problem?"

サインインしてコメントする。

採用された回答

Utpal Kumar
Utpal Kumar 2017 年 7 月 7 日
Edited and the delay time has been set to 0.1 seconds:
%draw rectangle and lambda
clear;
figure();
rectangle('Position',[0 2 10 1]);
axis off
set(gcf,'Position',[ -901 789 579 70])
t=0:0.05:3
l=1; a=0.5
p=@(t,l,a) 1-(1-a).*exp(-l.*t);
x=[0 0 10 10];
y=[2 3 3 2];
patch(x,y,'white');
frame=getframe(gca); im=frame2im(frame);
[imind,cm] = rgb2ind(im,256);
filename='bar.gif';
imwrite(imind,cm,filename,'gif','DelayTime',0.1, 'Loopcount',inf);
for tt=1:length(t)
pt=p(t(tt),l,a);
x=[0 0 10.*pt 10.*pt];
patch(x,y,'green');
% pause(.01); drawnow;
frame(tt)=getframe(gca);
end
for tt=1:length(t)
im=frame2im(frame(tt));
[imind,cm] = rgb2ind(im,256);
imwrite(imind,cm,filename, 'gif','DelayTime',0.1,'WriteMode','append');
end
  3 件のコメント
Diptangshu Paul
Diptangshu Paul 2022 年 9 月 14 日
How is delaytime 0.1 faster than delaytime 0?
DGM
DGM 2023 年 4 月 23 日
Short delay times depend entirely on the application to render them at the specified rate. It should be no surprise that at some point, the specified delay time fails to be met. While an exact zero delay time might seem a bit of a stretch, in practice it's worse than that. While most web browsers support delay times below 0.1s, most will treat 0 delay time as 0.1s. In other words, if you try to go too fast, you'll actually get slower results.
A number of people have surveyed this experimentally over the years. Here are two old ones that I found.
From the conclusion on the first link:
The first finding to note is that no modern browser surveyed supports frame delays below 0.02 seconds. Therefore, when creating an animated GIF, one should never use a frame delay below this threshold as it will be entirely ineffectual.
From the documentation for imwrite():
To achieve a high animation rate, set DelayTime to 0.02. Setting DelayTime to a lower value will slow down the actual animation rate in many image viewers and web browsers.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by