How can i find the resolution of an image?

Hi, how i can find the resolution of an image with matlab (number of pixels in millimeter). thanks

3 Comments

EASY:
use imfinfo() function and take
xresolution
and
yresolution field.
See solutions below. What imfinfo gives you might not always contain xresolution, and when it does, it may not be correct or what you think. For example
fi = imfinfo('cameraman.tif')
gives 72 inches. Obviously not correct or even applicable. However, it might be correct depending on the image capture system.
In my experience, XResolution and YResolution information returned by imfinfo() is wrong much much more often than it is correct.

Sign in to comment.

Answers (6)

Thomas
Thomas on 16 Nov 2012
Edited: Thomas on 16 Nov 2012
Use 'imfinfo'
E.g.
info = imfinfo('new1.jpg')
info =
Filename: [1x95 char]
FileModDate: '01-Oct-2001 17:19:44'
FileSize: 27387
Format: 'jpg'
FormatVersion: ''
Width: 600
Height: 650
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: ''
NumberOfSamples: 3
CodingMethod: 'Huffman'
CodingProcess: 'Sequential'
Comment: {[1x69 char]}
There you can fine the resolution widthxheight bit depth etc..

10 Comments

I used this line
info=imfinfo(im);
but i get this error
??? Error using ==> imfinfo at 80
Filename must be a non-empty string.
Error in ==> code at 8
info=imfinfo(im);
Apply it to a file name, not an image that has already been read into memory. Images read into memory do not have resolutions associated with them.
I get this result
Width: 750
Height: 498
BitDepth: 24
24 is the resolution?? It's the resolution of the image or the resolution of the device used in the acquisition? what's the difference between the resolution of the image and the resolution of the device?
24 is 8 bits per color plane, 3 color planes. It has nothing to do with spatial resolution.
When images include resolution in their header information (uncommon for regular cameras, but sometimes appear for scientific devices), it is the image resolution rather than the device resolution. Devices do not always do physical scanning or image acquisition in exactly the same way that the images are constructed, so the resolution reported has to be the effective resolution. Also, depending on what the device is, any particular saved image might be down-converted from what was saved by the device, so the reported resolution (if it is there at all) has to match the image, not what the device could give.
thanks, so what's the resolution from these informations
FileSize: 868582
Format: 'png'
FormatVersion: []
Width: 750
Height: 498
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: [137 80 78 71 13 10 26 10]
Colormap: []
Histogram: []
InterlaceType: 'none'
Transparency: 'none'
SimpleTransparencyData: []
BackgroundColor: []
RenderingIntent: 'perceptual'
Chromaticities: [0.3127 0.3290 0.6400 0.3300 0.3000 0.6000 0.1500 0.0600]
Gamma: 0.4545
XResolution: 3779
YResolution: 3779
ResolutionUnit: 'meter'
3779 pixels per meter, or 3.779 pixels per millimeter, according to that data.
why for some image imfinfo couldn't give me the XResolution?
Eric
Eric on 16 Nov 2012
Edited: Eric on 16 Nov 2012
That would make the pixels 264.62 microns across and the height of the detector (650 such pixels) 6.8 inches. I don't know whose camera this is, but that is almost assuredly not right.
-Eric
Good point, Eric. Carole, is the image of a single spot or is it of a larger area that you moved along?
Carole, XResolution is an optional EXIF tag. In most cases it is not known or not meaningful.
Sorry for the stupid questions but I like to understand. So what's the solution to convert a diameter of a region in pixel to millimeter. is there a trick using a regle of three for example? or what is the parameter necessary to make this conversion?

Sign in to comment.

Most often, you cannot figure out what the resolution of an image is.
If you are using a better-quality camera in auto-focus mode, the EXIF information might include the distance to the focus. If you have that and the lens aperture, then by knowing the height and width in pixels, you can calculate the angle subtended by the pixel range, and thus the angular resolution. (Perhaps you do not need the aperture; I have forgotten the details of the calculation.)
If you are using a medical device such as CT or MRI, then the images for those are usually created as DICOM images, for which there is DICOM meta-data that includes the resolution in the PixelWidth tag.

2 Comments

Carole
Carole on 16 Nov 2012
Edited: Carole on 20 Dec 2012
I do not know the resolution. I want to calculate the resolution from the image. Is this possible??
Eric
Eric on 16 Nov 2012
Edited: Walter Roberson on 24 Aug 2019
It looks to me like the device has no imaging capability ( http://www.delasco.com/pcat/1/Diagnostic/Delta20/Delta20/ ). You need to pair it with another camera. I would say your best bet would be to do your own calibration of the systems. You could buy a resolution target (something like an Air Force 1951 resolution target from Edmund Optics) that has small features of known sizes. Image them and determine what the resolution is that way.
-Eric

Sign in to comment.

Carole
Carole on 17 Nov 2012
Edited: Carole on 17 Nov 2012
I'm looking for the solution to convert a diameter of a region in pixel to millimeter. is there a trick using a regle of three for example? or what is the parameter necessary to make this conversion? I have these informations but I don't know how can I use it:
-the resolution of the device is 41.1 megapixel
-1 megapixel = 0.264 mm
-1 dpi = 3.937 pixels/mm

7 Comments

Those numbers are inconsistent. In particular there must be a problem with the second figure. 41.1 megapixel is a measure of area, not of length, but the second line is megapixels to length.
The 3.937 pixels/mm indicated here is suspiciously like the 3.779 pixels/mm that we calculated above.
To get the right number of megapixels, estimating the aspect ratio as 3/2 (as in the 498 x 750 image above) would require about 5230 x 7845, and at 3.937 pixels/mm that would be over 20 meters on the shorter side.
To summarize, in general what are the parameters necessary to do this conversion from pixel to millimeter (find the diameter of a region)?? I found in some sites that 1 millimeter = 3.779527559 pixel. Can I so fix this parameter at 3.779527559?? knowing that the focusing lens of the device is with 10 x magnification, can i do this:
result= (diameter/3.779527559)/10
I need your help please to solve this problem
No. You need to have some object or length in your image that you know what the length is and then measure it. I wouldn't trust anything that's in the metadata/exit unless it's from a calibrated system (CT, MRI, microscopy).
3.779527559 is exactly the figure for 96 pixels per inch. Which is a common screen resolution, but not a common camera resolution. The magnification is irrelevant: pixels divided by 96 equals inches.
The only time magnification would be important would be if the image you get is of a 10x magnification of the 96 pixels/inch. In that case, 96*10 image pixels would be 1 inch of original size. Alternately, it could be the case that the original surface is magnified 10x and then the 3.779 pixels/mm (96 dpi) is what the magnified image is recorded as, so getting an actual resolution of 37.79 pixels/mm.
I don't know the length of any object in the image. Can I use the length and height of the image. There is no other solution ??? I foud in other images (using the same device) that a width of an object is 10 pixels or approximately 0.22 mm. Can i use this parameter?
How about you tell us the make and model of what you are using, so we can see if we can understand the manual?
If you have studied the Digital Image Processing by Gonzalez Book. You understand that 'Resolution can't be explicitely mentioned using the pixels. It has to be mentioned along with dpi value'. For exmaple 512*512 image with 72dpi has better resolution compared to 512*512 image with 36dpi

Sign in to comment.

Image Analyst
Image Analyst on 18 Nov 2012
Edited: Image Analyst on 18 Nov 2012
Carole, Sure, go for it. So multiply any lengths in pixels by 0.022 to get length in mm, and multiply and area in pixels by 0.022^2 to get area in mm^2. Of if you know the length and height of the total image field of view then you can use that too. For example, if the height = 960 pixels and it's 21 mm. Then the spatial calibration factor is 21/960 = 0.021875 mm per pixel. So let's say an object is 342 pixels long, well that's 342 * 0.021875 = 7.48125 mm long. If the area = 20,000 pixels, it's 20,000 * 0.021875^2 = 9.57 mm^2 in area.

10 Comments

If i will use the height of the image to calculte first the calibration factor, I will do this First i used this link http://www.unitconversion.org/typography/pixels-x-to-millimeters-conversion.html I found that 1mm=3.779527559 pixel so:
[L C]=size(I);
m=3.779527559;
L2=L/m;
calib=L2/L;
diam2=diam*calib
Is this correct?
No, that's not. You can't use any number that you look up somewhere. They have no idea what you imaged or the spatial calibration that may be needed. You can't trust the camera either unless it's a calibrated system like CT, MRI, or Microscopy where they make sure to embed the accurate spatial calibration in the header or EXIF info. Let's say that you took a picture of me standing in front of a bunch of trees with the moon overhead. Your camera will tell you the resolution in terms of pixels - how many pixels tall and wide your image is, but the number of millimeters one pixel corresponds to depends on what you're looking at. Even though you have the same camera with the same focal length and same CCD size, one pixel on me might be 2 mm, while one pixel on the tree in the distance behind me might be 200 mm, and one pixel on the moon might be 200 kilometers if you were measuring something on the moon. That's why you need to measure some known length (like a ruler) and that's why that spatial calibration only applies in the imaging plane where the thing was measured, not for anything closer or farther away. Does that help illustrate the issue to you better?
Knowing the equipment make and model would help a lot.
Something doesn't add up. You say the image is 498 rows by 750 columns. The spec sheet says "40 mm Field of View (flat field)" which would give a 40/750 = 0.053 mm per pixel. But the spec sheet also says "DermaScout Dermatoscope measures in 0.1 mm increments" and "Measures in .005" increments" which are pretty vague. If they give resolution, they usually give the pixel width. But they give about twice the pixel width. If you don't give the pixel width then they usually give the 10% point of the MTF. Bottom line, this thing has a marked reticle in it so why can't you just use that to find out the true spatial calibration.
The reason they don't give pixel width (it seems to me) is that that device does not take images. No camera attachment, no interfaces noted. It is, it looks to me, a hand-held device with some kind of markings to allow you to estimate sizes.
That's mean that there is no solution? :( I'm not sure about the characteristics of the device used for some images. So I need a calculation independently of the device used. what are the settings required? What is the formula for the calculation? I found these links but I couldn't use these informations
The UNICO dermatoscope that you linked to has no way of taking images. It is also only 6x rather than the 10x you referred to earlier. These factors suggest that you indicated the wrong dermatoscope to us. For example the Heine Delta 20 that the store also sells is 10x and has some kind of provision for photography.
All three of the dermatoscope that store sells are marked as being for sale in USA only; I have formed the impression that you are in France instead ?
Carole, how did you say this earlier:
I get this result
Width: 750
Height: 498
BitDepth: 24
Evidently you have some kind of camera hooked up to this loupe and are able to take pictures somehow. Please take a picture of something with the reticule in place, and upload it, so we can measure the spatial calibration.
Especially a picture of something of known size, such as a ruler.
The how did you get the pictures? Did you get them from that dermascope or not? If not, where did they come from and what does the dermascope have to do with anything?
And the print size has nothing at all to do with any kind of distance in your image. I could print a picture of a galaxy and a picture of a virus both on the same size paper printout with the same size image pixel dimensions. But of course their spatial calibration is vastly different.

Sign in to comment.

I'm sure you can get the FOV size from the Dicominfo.
If the FOV is 400 mm, matrix is 512 by 512; then the Resolution = FOV/matrix = 400/512 = 0.7813 mm/pixel.

1 Comment

Unfortunately the person was working with a png not with a dicom image.
Looking at the fov is typically the wrong way to get sizing from dicom images. The best way depends upon what kind of image it is. I do not recall the best way for CT. MRI images have a pixel centre to centre for x and y that can be used. (The tricky part is determining the z resolution)

Sign in to comment.

Ιs it possible to find the real image dimensions of a .jpeg, through the XResolution and the YResolution given from the imfinfo function, without the pixel/mm reconstruction factor? Τhank you in advance

6 Comments

No. If your JPEG image does not have additional EXIF information recorded that would allow you to compute the pixel/mm somehow (such as focal distance and lens aperture) then chances are high that whatever XResolution and YResolution it has recorded are nominal values, such as the equivalent of 96 dpi, that have nothing to do with the actual image resolution.
Thank you very much, Walter, for your instant answer!
Imagine you were in your backyard holding up a poster of the moon and taking a video or photo. One pixel might represent millimeters on the poster and the field of view might be a meter. Now imagine you yanked away the poster and revealed the real moon in the sky behind it. Now a pixel correponds to kilometers on the real moon and the field of view could be tens of millions of kilometers.
Could you please explain me the most common mathematical type of convertion the dimension of a .jpeg from pixel to mm, which correlates focal length or lens aperture with the dimensions? Thank you in advance!
No. It's not possible. There is no such conversion that works for all or most jpg images and all/most fields of view. You have to calibrate your specific image. See attached spatial calibration demo.
You would need to know the distance between the image sensor and the lens:
When f is the focal length and is the distance between the sensor and the lens, and is the distance between the lens and the object being photographed, then
By knowing the image sensor physical size, and its resolution, and the portion of the image that the object of interest occupies, you can determine the physical size of the sensor portion covered by the projection of the image. Then you can use the recorded readings such as aperture and distance to the target together with the optical formulas, to figure out what the physical size of the distant object must have been. You then combine the physical size of the object with the number of pixels needed to represent it to find the resolution.
Alternately if you know the physical size of the object and the number of pixels needed to represent that size, you can directly calculate resolution.
The further you get from the object, the more imprecise the calculations get. It doesn't take much in casual photography before is sufficiently smaller than as to get lost in the noise of the imprecision of measuring

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Tags

Asked:

on 16 Nov 2012

Commented:

on 27 Nov 2022

Community Treasure Hunt

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

Start Hunting!