Is it possible to create 24-bit gif in Matlab?

I would like to create 24-bit animated gif from figure. Is it even possible in Matlab?
Below part of my code:
current_frame = getframe(fig3D);
[frame_indices, cmap] = rgb2ind(current_frame.cdata,256,'nodither');
movie_frames = repmat(frame_indices,[1 1 1 movFrames]);
for ii = 1:movFrames
[...]
ff = getframe(fig3D);
[movie_frames(:,:,1,ii),cmap] = rgb2ind(ff.cdata,cmap,'nodither');
end
imwrite(movie_frames,cmap,[movFilePath,'\',movFileName],'DelayTime',0,'LoopCount',inf);

 Accepted Answer

24 bit GIFs are implemented as a multi-frame GIF without a time delay between the parts. For each frame of a picture a 8 bit color map can be created, if it is small enough. So the program must split the image into appropriate parts and save them as frames of an animated GIF and set the delay to zero. See https://en.wikipedia.org/wiki/GIF#True_color
Many browsers and e.g. Photoshop can read an display such 24-bit GIFs, but the definition is at least awkward. I do not know a method to create such GIFs in Matlab, and I would hesitate to create one, because PNGs are smarter.

More Answers (1)

6 Comments

In your link there is information about displaying GIF images - I want to save them in True Color (24-bit) from figure.
It is not possible directly as the color palette for GIF is 8-bit (256 colors). That is why I am asking if there is a method for Matlab it the way I want.
I've never tried to make gif's from a figure, or even from an image for that matter. If anything could do it, it would be export_fig(): http://www.mathworks.com/matlabcentral/fileexchange/23629-export-fig
The "imformats" command shows that imwrite() will also create gif images, though that would be from an image array variable, not from a figure window with all the axes tick marks and labels and annotations in the overlay, etc.
I have presented sample code for obtaining figure image with getframe() function and capturing series of those frames later saved as a GIF file.
My question is about the possibility to have True Color (24-bit) colormap instead of 8-bit (256 colors).
The solution, or should I say "bypass", I am using now is to record movie instead of GIF and then convert it into GIF using external software. Still I would like to do it all in Matlab if possible.
I don't understand your question. As you've stated yourself, the GIF format only allows 256 colours per frame (note that each colour is an 8-bit RGB triplet, so the colours themselves could be said to be 24-bits).
This is a restriction of the format. There is no way for matlab or any other program to create a GIF that bypass that restriction, otherwise it's not a GIF anymore.
As far as I know, there is no widely supported alternative to GIF other than video formats.
I didn't know either but after reading Guillaume's answer I thought I'd check PNG since it's pretty much become/becoming the new defacto standard, and sure enough, there's an animated PNG: https://en.wikipedia.org/wiki/APNG
The Animated Portable Network Graphics (APNG) file format is an extension to the Portable Network Graphics (PNG) specification. It allows for animated PNG files that work similarly to animated GIF files, while supporting 24-bit images and 8-bit transparency not available for GIFs. It also retains backward compatibility with non-animated PNG files.
The first frame of an APNG file is stored as a normal PNG stream, so most standard PNG decoders are able to display the first frame of an APNG file. The frame speed data and extra animation frames are stored in extra chunks (as provided for by the original PNG specification).
APNG competes with Multiple-image Network Graphics (MNG), a comprehensive format for bitmapped animations created by the same team as PNG. APNG's advantage is the smaller library size and compatibility with older PNG implementations.
Yes, APNG would be the best choice, but as far as I know it is not implemented in Matlab.

Sign in to comment.

Categories

Products

Asked:

on 3 Nov 2015

Commented:

on 10 Nov 2015

Community Treasure Hunt

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

Start Hunting!