Saturday, November 2, 2024
HomeMatlabPuzzles About GIF DelayTime » Steve on Picture Processing with MATLAB

Puzzles About GIF DelayTime » Steve on Picture Processing with MATLAB


[TLDR: To create a fast GIF animation using imwrite, use a DelayTime of 0.02 instead of 0.]

In my 28-Feb-2022 publish, I confirmed some code that created an animated GIF file utilizing a DelayTime of 0.

im = rand(750,750)>0.8;

for ok=1:500

t = conv2(im(:,:,ok),[2,2,2;2,1,2;2,2,2],‘identical’);

im(:,:,1,ok+1) = (t > 4) & (t < 8);

finish

imwrite(~im,‘life.gif’,‘DelayTime’,0,‘LoopCount’,1)

In response, reader Mikhail commented that one should not use a DelayTime of 0 for the aim of making quick GIF animations. He pointed me to an weblog publish by Ben Phelps known as “The Quickest GIF Does Not Exist.” (Observe: In the event you go to this web site, you could get a safety warning in your browser. Apparently, the location’s certificates expired a number of days in the past. Go to at your individual threat. I’ve tried to contact the writer to allow them to know.)
A few years in the past (about 25!), I used to work on picture file format assist in MATLAB, so I often begin investigating such questions by wanting on the specification for the format in query. The related spec is GIF89a, and here is the important thing paragraph:

Discover that this language does not specify precisely what is meant to occur if the Delay Time is 0.

One factor I’ve realized by expertise is that the precise habits of generally used software program purposes generally varies from the spec, and implementers should take note of that. Ben has regarded on the publicly out there supply code for a number of browsers and different purposes and found a Delay Time of 0 or 1 (1/100 s) is usually not honored. As a substitute, for numerous sensible and historic causes, a really low Delay Time like 0 or 1 is usually bumped up arbitrarily to a worth of 10 (1/10 s).

Subsequently, setting Delay Time to 0 is just not going to provide the quickest potential animation! I examined this in Safari, the browser I exploit on my Mac, and this does look like true.

This GIF was generated utilizing DelayTime of 0:

life (delay time = 0).gif

This one was generated utilizing a DelayTime of 0.02 (imwrite makes use of seconds as a substitute of hundredths of seconds for this parameter):

life (delay time = 0.02).gif

Certainly, the second model does animate way more rapidly.

One implication is that we may have to vary the imwrite documentation, which particularly says to make use of DelayTime of 0 to get the quickest animation:

I really suppose it might be time to vary the imwrite interface. Maybe we might give this parameter a reputation, akin to FrameRate, (in frames per second) and doc a most worth of fifty (which corresponds to a DelayTime of 0.02 s (or 2 hundredths of a second).

I’ll make each ideas to the event crew liable for imwrite.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments