Saving your time-lapse videos in a gif file

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 editor that supports animated gif files. Its frame rate in this example is dependent on the frame rate of the original video. In general, the playback frame rate of gif files can be affected by other factors as well, for example, the browser that plays the gif.

Pop quiz – image filtering in 2-dimensions

Q1. Which of the following are true?

  1. implay is a tool supporting image processing tasks.
  2. A gif file is a static image format that is rarely used.
  3. Interlaced videos have double the information that progressive videos of the same size and frame rate have.
  4. A higher frame rate leads to a smoother depiction of motion.
  5. A struct variable can be a matrix containing fields of different types.
  6. Function aviread can read compressed videos in Unix systems.
  7. Function VideoReader is the most recent video reading function in MATLAB and therefore it is the safest choice for such tasks.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset