Save a .fig image to a .jpg image while maintaining size and resolution

I report the code I am using.
open_fig = openfig('figure_fig.fig');
filename = 'figure_jpg.jpg';
saveas(open_fig, filename);
open_jpg = imread('figure_jpg.jpg');
figure();
image(open_jpg);
I do not understand why the .jpg figure I am going to show does not keep the same size as the .fig figure (449x512x3 uint 8). The .jpg figure has, with this code, the dimensions 704x870x3 uint 8 quite different from those of the .fig figure.
I tried using the imresize command but it did not bring any results.
B = imresize(open_jpg,[449 870]);
figure();
image(B);

2 Comments

Do you want to save the contents of the figure or of the axes?
JPEGs do not store a resolution, but a certain number of pixels.
@Jan, I want to save only the figure (characterized by pixels).

Sign in to comment.

 Accepted Answer

Unless you have some sort of complicated composition of images and plots and annotations in the figure, avoid saving images by saving the figure/axes. Save the output images directly using imwrite(). Saving images by capturing the figure is equivalent to taking a screenshot. It's needlessly destructive and difficult to control.
Considering that your images have fairly sharp edges and a lot of contrast, I strongly urge that you don't use JPG. This sort of image is where JPG performs worst, and the parameters used for saving JPG in MATLAB result in even lower fidelity than most users would expect from other applications.
On the bright side, PNG is widely supported, lossless, and the compression algo should work well on images like these with broad flat color regions.
imwrite(outpict,'mypicture_001.png')

More Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Products

Release

R2021b

Asked:

on 29 Oct 2022

Edited:

DGM
on 29 Oct 2022

Community Treasure Hunt

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

Start Hunting!