How can I save high resolution image with original size and quality?
18 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ferit Akgul
le 18 Fév 2018
Modifié(e) : Ferit Akgul
le 19 Fév 2018
Hi,
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:
hread=imread([fname]);
[height,width,dim]=size(hread);
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?
Thanks
2 commentaires
Rik
le 19 Fév 2018
Saving through a figure can be very tricky. Often the easiest solution is to not use the figure, but modify the image itself (as loaded into a matrix). It is then trivial to write out the modified image with the same resolution: it's the default for imwrite.
Réponse acceptée
Plus de réponses (1)
Image Analyst
le 19 Fév 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.
Voir également
Catégories
En savoir plus sur Convert Image Type dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!