Is it possible to create 24-bit gif in Matlab?
Show older comments
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
More Answers (1)
Image Analyst
on 3 Nov 2015
0 votes
6 Comments
Michal Dudek
on 3 Nov 2015
Image Analyst
on 3 Nov 2015
Edited: Image Analyst
on 3 Nov 2015
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.
Michal Dudek
on 10 Nov 2015
Guillaume
on 10 Nov 2015
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.
Image Analyst
on 10 Nov 2015
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.
Michal Dudek
on 10 Nov 2015
Categories
Find more on Animation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!