Another very popular format that incorporates motion is the graphics interchange format, shortly known as gif. This is a widely used file format, which supports up to 8-bits per pixel for each color channel. It can be used for still images, but also for animation. Gif files are very frequently used in the internet due to their simplicity and portability, which allows for easy production of animations made from photographs, plots, or sketches. In MATLAB, we can make a gif file using imwrite
.
To save our time-lapse video generated in the previous example in a gif file, we have to repeat step 4, this time using imwrite
:
>> fl = 'gifTimelapse.gif'; >> for i = 1:size(v,4), [imind,cm] = rgb2ind(v(:,:,:,i),256); % Change rgb frame to indexed image if i==1, imwrite(imind,cm,fl,'gif', 'Loopcount',inf); else, imwrite(imind,cm,fl,'gif','WriteMode','append'); end end
The file we created, called gifTimelapse.gif
, can be opened using any photo...