Can't save image with 300 dpi
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mubashir
am 20 Feb. 2022
Kommentiert: Walter Roberson
am 20 Feb. 2022
I am using matlab R2020b-academic use.
bar([1 11 7 8 2 2 9 3 6])
f = gcf;
exportgraphics(f,'barchart.jpg','Resolution',300)
print(gcf,'fig1.jpg','-djpeg','-r300');
I have tried to use export_fig, exportgraphics, and print command to save iamge with 300 dpi. But non of them are working.
Besides I used same code several months ago and it was working perfectly, now it is saving image with 96 dpi by default. I have tried malab given examples for saving images for higher resolution, but same problem.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 20 Feb. 2022
You are confusing the resolution stored in the Exif information in the file, with the resolution actually saved at compared to the on-screen size of the image.
You should probably have a look at your figure PaperPosition https://www.mathworks.com/help/matlab/ref/matlab.ui.figure-properties.html#buiwuyk-1-PaperPosition and PaperUnits . The PaperPosition and PaperUnits together determine the physical size aimed for, and the 'Resolution' or -r option determine the dots per inch compared to the PaperPosition . But what gets written into the header of the file is not necessarily related to any of that.
You should distrust the Exif resolution of any image file except sometimes photos created by "Pro" cameras, or created by scientific instruments.
3 Kommentare
Walter Roberson
am 20 Feb. 2022
You are looking at the Properties of the image. Windows looks inside the image file for a block with the tag EXIF to find the properties. The EXIF block is a standard on how to store data with image files.
Each EXIF block is made up of an ID number that identifies which property is being referred to, and a bit of information about the amount of memory used to hold the property information, and then data indicating the value stored for the property.
All information in EXIF blocks is narrative, information added on because it can be useful to know. EXIF data never controls the actual image. EXIF is like a label on a box. The label can be wrong. The label can be thrown away without changing what is really in the box. For example the EXIF data might say that the image is 512x512, but when you look inside the data the image might be a different size completely. The actual data is what is correct; the EXIF information is just whatever best-guess was written on the outside.
Windows always trusts the label (EXIF information) when it shows you the properties. MacOS is more likely to look inside the data to see what is really there.
When JPEG files are written, it is common for XResolution and YResolution properties to be stored. But most of the time, the resolution information written with JPEG files is nonsense. On Windows, most programs just always write in either 96 dpi or 100 dpi. On MacOS, most programs just always write in 72 dpi.
Again, the EXIF information is just for human convenience, and may be wrong. It does not affect anything about the image except to confuse humans.
It happens that some fundamental properties such as image height and width and gray vs color can be determined from the data itself while ignoring the EXIF information. But it also happens that resolution is not fundamental information about an image, and might be be stored with the actual image data at all. The EXIF information about the resolution might be the only information about the resolution there is... but what is stored in the EXIF is a made-up number most of the time.
Walter Roberson
am 20 Feb. 2022
So, there are two completely different questions involved:
1. Can you generate an image with the resolution you want; and 2. Can you have that resolution written into the file so that Windows will show it to you when you look at the file properties.
MATLAB does not provide any method to write EXIF information for JPEG files. There is a File Exchange Contribution of code that can invoke an external program to write EXIF information; the executable has to be installed separately.
My understanding is that Mathworks chose the JPEG writing library that it chose because the library was considered reliable and relatively secure. But I am not sure that library supports writing arbitrary EXIF information. Some of ones that do support writing arbitrary EXIF are considered less reliable.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!