saving an image to disk

10 visualizaciones (últimos 30 días)
Karan Ratnaparkhi
Karan Ratnaparkhi el 27 de Abr. de 2011
Editada: DGM el 3 de Jun. de 2021
Hi guys, after some processing i am getting an image and now I want to save it to my disk in .png format. Plz tell me which function should I use?

Respuestas (2)

Chirag Gupta
Chirag Gupta el 27 de Abr. de 2011

Rahul punk
Rahul punk el 2 de Jun. de 2021
Editada: Rahul punk el 3 de Jun. de 2021
%read image
tt= imshow(image) ;
%save your image other location with any name save desktop or any folder also
saveas(tt,'C:\Users\admin\Desktop\testimagesave.png') ;
  2 comentarios
Rik
Rik el 2 de Jun. de 2021
This uses a much more complex method, making it much slower. It also risks changing the apearance of the image, as well as adding a border around the axes containing the image.
Also, the question asked for a png, so I don't see why you chose jpg in your example. I would also discourage using imshow to read an image from disk. It is much clearer what is happening if you use imread.
DGM
DGM el 3 de Jun. de 2021
Editada: DGM el 3 de Jun. de 2021
To emphasise what Rik mentioned, by default, imshow() uses nearest-neighbor interpolation to display the image. Even disregarding the added padding, the actual size of the image will depend on the figure geometry. If it is resized, it will be subject to all the degradation associated with nearest-neighbor interpolation. For example:
% generate a 500x500 1px checkerboard pattern
x = mod(1:500,2);
y = mod(1:500,2);
inpict = xor(x,y');
% look! it's perfect!
imwrite(inpict,'justwritethefile.png');
Okay, maybe it doesn't look perfect, but that's just the website messing with how it's displayed. Just right click > view image to see it straight.
If you use imshow(), this is what you get. I added 1px black border so it's easier to see how big it is against the webpage bg.
tt = imshow(inpict);
saveas(tt,'whywouldyoudothis.png')
Go ahead and right click > view image on this one. Look at all that padding. Look at all the interference. This is not a negligible or reversible amount of damage. Could some of this be avoided by getting the figure geometry just right? Sure, but the figure geometry can't always be right, and there's no reason to add the extra complexity for a small improvement upon a self-made problem.
Add to this the fact that imshow() can't handle alpha content, so any alpha content will be lost. Similarly, any indexed image saved this way will no longer be an indexed image -- something which imwrite supports for PNGs.

Iniciar sesión para comentar.

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by