Why imwrite generated gif files are smaller than they look like on the screen

I fixed the display figure size on screen by using
set(gcf,'Position',[200,200,1000,1000])
Then I used imwrite to create gif animations. However, the generated gif are so small, around 800*768.
How can I let the imwrite to generate the gif file with the same displayed figure as it is on screen ?
Many thanks

3 Commenti

Update:
After around 10 hours investigating this this issue, I have figured out a general solution for generating a gif animation at a fixed windows size:
1. in Matlab, fix the figure size. 2. in the for loop, save each single frame to a jpeg file (I use jpeg because it has the smallest size) 3. use another for loop to combine these jpeg files to a single gif animation by using imread and imwrite.
Why I use above routine? Because I find that getframe only captures the last subplot if the figure contains multiple subplots. I have tried getframe(gcf) with no success. This is really annoying!
Hopefully my solution works for others
Nice solution Kyle of nine years ago, worked for me!
Using JPG for intermediate file storage in the middle of a processing pipeline is a very bad idea, especially in this context.
Most of the things you're capturing from a figure will be hard edges and narrow lines with equally rapid chroma swings. MATLAB saves JPG (both when saving figures or using imwrite()) at 75% quality with 4:2:0 chroma subsampling. You can't really ask for a worse application for JPG than figure capture in MATLAB.
If the thing being displayed is just an image, save it with imwrite(). If the thing you're trying to save is a plot or something, you can always use getframe or exportgraphics to get an image, which can then be resized or post-processed as needed. If you want to use the temporary file approach described above, just use PNG. Saving a marginal amount of disk space shouldn't be a concern, since they're temporary files. Depending on the image content, you may find that the PNGs are actually smaller.

Accedi per commentare.

 Risposta accettata

imwrite() does not write according to the size of the window: it writes according to the size of the matrix you pass into it.
You could perhaps getframe() and imwrite() that, but if you do then what will be written out is the array you are displaying just magnified to the axis size. You could instead do that kind of magnification after you have written the original image.

Più risposte (0)

Categorie

Scopri di più su Environment and Settings in Centro assistenza e File Exchange

Richiesto:

il 19 Ago 2013

Modificato:

DGM
il 26 Apr 2022

Community Treasure Hunt

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

Start Hunting!

Translated by