MATLAB Answers

How can I save high resolution image with original size and quality?

23 views (last 30 days)
Ferit Akgul
Ferit Akgul on 18 Feb 2018
Edited: Ferit Akgul on 19 Feb 2018
I'm trying to save a high resolution image (trial.png) that I load into a figure and edit (modify some pixels).
The code is:
res = get(0,'screenpixelsperinch');
% for keeping original image size
set(gcf, 'PaperUnits', 'inches', 'PaperPosition', [0 0 width height]/res);
% for margin removal
horg = get(gca,'position')
set(gca,'position',[0 0 1 1],'units','normalized')
dirname = dir;
filename = fn;
print(gcf,'-dpng', '-noui',fullfile(dir,fn),['-r' num2str(res)])
When I save the image either using print or export_fig (export_fig_out.png), image resolution comes out the same however image looks very pixelated.
How do I make sure image is saved with the properties of the native image?
Ferit Akgul
Ferit Akgul on 19 Feb 2018
Thanks Rik. I thought about it too, however, it used to work with this method before on an earlier version of Matlab. Now I'm using 2016a. I haven't changed the code in any way. Working with the figure is more practical since I'm doing edits using the GUI directly.

Sign in to comment.

Accepted Answer

Ferit Akgul
Ferit Akgul on 19 Feb 2018
Edited: Ferit Akgul on 19 Feb 2018
I believe I found a way. Based on Rik's and Image Analyst's answers I had to rewrite some portion of my code to use the following commands to get the job done directly on the image matrix:

More Answers (1)

Image Analyst
Image Analyst on 19 Feb 2018
Like Rik says, use imwrite() to save the original image rather than a .fig. You can always call imread() and put it into a new figure/axes if you want. I don't see how importing a pre-drawn figure would make it easier for you to do your edits in your GUI rather than reading an image directly into the axes control on your GUI window.
  1 Comment
Ferit Akgul
Ferit Akgul on 19 Feb 2018
Hi Image Analyst,
Thanks a lot for the suggestion. The hard part comes in when I put a LOT OF edits (text, line, circle etc) on the imported figure and then save it. Attached's an example.
If there's an easy way to modify the image matrix to accommodate all the texts, lines etc I'd be happy to try this method as well.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by