how to save image
291 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
hai..
how to save image that pop up at frame show figure. I try to used this function,but the saved image not follow the dimension(X x Y) of original image.
saveas(gcf,'mask_image.jpg', 'jpg')
thank
0 comentarios
Respuesta aceptada
Jan
el 9 de Dic. de 2011
Image = getframe(gcf);
imwrite(Image.cdata, 'mask_image.jpg');
Another method:
printf(gcf, '-djpeg100', 'mask_image.jpg', '-r0');
But the later is not guaranteed to have exactly the same size. There are some rounding effects between the units of the figure and the pixel resolution.
3 comentarios
Clinton Connelly
el 30 de Sept. de 2021
You could just use the built-in "imwrite" function to save any loaded image, or specifically a 'uint8' file, to a file of any choice:
Image = imread("ImageName.jpg");
imwrite(Image, "NewImageName.jpg");
This code doesn't return the max resolution of the file, but there is a parameter for that:
Image = imread("ImageName.jpg");
imwrite(Image, "NewImageName.jpg", "Quality", 100)
The interval of values for quality is between 0 and 100, inclusive, with the result being self-explanatory
Other information could be found in matlab by typing the input "help imwrite" and doing some reading...
There's also a text file called libtiffcopyright.txt, but I don't know where to find that
DGM
el 24 de Jul. de 2024
Editada: DGM
el 24 de Jul. de 2024
Using figure capture to JPG for saving images is only a smidge less ridiculous than using your phone to take a skewed photo of your monitor.
I second @Clinton Connelly here. Depending on the scenario (version, environment, image size, figure style), neither saveas(), print(), nor getframe() are guaranteed to return an image of the correct geometry. The data scale, class, and number of channels may be altered. The image resolution will be altered, and there will likely be a random amount of padding added. There is rarely a good reason to save images by taking a screenshot. Just use imwrite().
To make matters worse, it's implied by the naming that this image is a binarized image. I see no good reason to be saving binary images as JPG. A PNG is lossless and will produce a smaller file with flat-colored image content. Even if it's not binarized, I'm still going to assert that most people are not making an informed decision to permanently damage their images with a downsampled JPG.
Setting the 'Quality' parameter to 100 does not create a faithful reproduction. The only way to produce a lossless image with full spatial resolution in the chroma channels is to specify the 'lossless' flag, which (iirc) produces a JP2 file instead of a baseline JPG. Everything else that imwrite() produces is a 4:2:0 downsampled JPG, even at 100% quality.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!