Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can i get the resolution of a jpg image with matlab?

1,369 views
Skip to first unread message

Azoun

unread,
Mar 12, 2011, 6:13:16 AM3/12/11
to
Hi to anyone,

in Matlab I cant't read the image resolution of a jpg file with the
command infinfo.

If I right-click on the file and see his properties, I can see the
image resolution. Why can't Matlab read it?

Is there a way to do so?

Thanks in advance

Azoun

ImageAnalyst

unread,
Mar 12, 2011, 8:16:07 AM3/12/11
to

------------------------------------------------------------------------------------------
rgbImageInfo = imfinfo('C:\Program Files\MATLAB\R2010a\toolbox\images
\imdemos\office_4.jpg')
fprintf('The Width=%d\nThe Height=%d\n',...
rgbImageInfo.Width, rgbImageInfo.Height);


rgbImageInfo =
Filename: 'C:\Program Files\MATLAB\R2010a\toolbox\images
\imdemos\office_4.jpg'
FileModDate: '09-Nov-2007 15:21:56'
FileSize: 141990
Format: 'jpg'
FormatVersion: ''
Width: 903
Height: 600
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: ''
NumberOfSamples: 3
CodingMethod: 'Huffman'
CodingProcess: 'Sequential'
Comment: {}
DigitalCamera: [1x1 struct]

The Width=903
The Height=600

Azoun

unread,
Mar 13, 2011, 6:56:15 AM3/13/11
to
Probably i wrote wrong my prevoius message.

I meant to resolution in dpi.

Yes I can read the number of pixel in X and Y direction, but I would
like to know the number Dots Per Inch of a jpg file


Many thanks

Azoun

Nasser M. Abbasi

unread,
Mar 13, 2011, 7:30:10 AM3/13/11
to

Do rgbImageInfo and look for the XResolution and YResolution. These are
the DPI values

EDU>> rgbImageInfo = foo.jpg')
rgbImageInfo =
Filename: 'foo.jpg'
FileModDate: '13-Mar-2011 04:23:00'
FileSize: 60932
Format: 'jpg'
FormatVersion: ''
Width: 415
Height: 205


BitDepth: 24
ColorType: 'truecolor'
FormatSignature: ''
NumberOfSamples: 3
CodingMethod: 'Huffman'
CodingProcess: 'Sequential'
Comment: {}

Orientation: 1
XResolution: 100
YResolution: 100
ResolutionUnit: 'Inch'
Software: 'Adobe Photoshop CS Macintosh '
DateTime: '2009:07:13 16:23:06 '
DigitalCamera: [1x1 struct]
ExifThumbnail: [1x1 struct]


To change DPI, I use IrfanView. It is free software. Open the jpg file
in it, then do image->Information, you'll see the DPI there. Change it
as needed, then make sure to save the image.

--Nasser

Igor

unread,
Jul 29, 2012, 8:04:13 AM7/29/12
to
I've got the same problem: DPI is shown in windows dialog, but is missing in imfinfo struct.
See screenshot:
http://img204.imageshack.us/img204/5440/capturezft.png

This occures with jpg files, png & tiff work OK.

Any alternatives?

Also, there's nothing about "XResolution" in official iminfo documentation:
http://www.mathworks.co.uk/help/techdoc/ref/imfinfo.html.

So, there's no documented way to read DPI?

Barry Williams

unread,
Jul 30, 2012, 11:59:12 AM7/30/12
to
"Igor" wrote in message <jv38rt$lnv$1...@newscl01ah.mathworks.com>...
Depends what you mean by dpi. What are you trying to do with the images? It really doesn't mean a lot beyond scaling for display or printing. Depending upon the version of jpeg used, the dpi is not always encoded, although when you look at the properties in Windows, the OS will 'invent' a resolution related to screen display (generally 72 dpi).
Barry

Igor

unread,
Jul 30, 2012, 6:04:07 PM7/30/12
to
"Barry Williams" <barry.r.wil...@saic.com> wrote in message <jv6b0g$1g$1...@newscl01ah.mathworks.com>...
Hi Barry, thanks for your answer!

> Depends what you mean by dpi. What are you trying to do with the images?
I need to know physical size of the image.

>Depending upon the version of jpeg used, the dpi is not always encoded, although when you look at the properties in Windows, the OS will 'invent' a resolution related to screen display (generally 72 dpi).

DPI shown on screenshot (10556) is valid, and it's nothing related to screen resolution :)
The thing is, matlab (R2012a) is unable to read this info...

Barry Williams

unread,
Jul 31, 2012, 7:39:15 AM7/31/12
to
"Igor" wrote in message <jv70cn$s08$1...@newscl01ah.mathworks.com>...
Okay, you're going to need to get some help from someone else. There is information you are not telling us. From the link that you gave earlier, I can guess that this may be some sort of mapping of a scene in the infrared at 2.4 µm, although it's still not clear to me how the resolution you showed before, 10556 dpi relates to the physical size of an image as printed or displayed--the usual meaning of dpi. This is equivalent to more than 1000 km on a side! How are the images recorded?
Barry

Igor

unread,
Jul 31, 2012, 8:55:14 AM7/31/12
to
"Barry Williams" <barry.r.wil...@saic.com> wrote in message <jv8g53$7sk$1...@newscl01ah.mathworks.com>...

> From the link that you gave earlier, I can guess that this may be some sort of mapping of a scene in the infrared at 2.4 µm

It's an X-ray micro-CT image.
0.0254/10556 = 2.4062e-06 ~ 2.4 µm is an image voxel size. DPI=10556 ,not wavelength of something...



>although it's still not clear to me how the resolution you showed before, 10556 dpi relates to the physical size of an image as printed or displayed--the usual meaning of dpi.

I just need to know image voxel size, I'm not going to print it...



>This is equivalent to more than 1000 km on a side!

Why 1000km? You're right, image voxel size is about
0.0254/10556 = 2.4062e-06 %meters
I.e. physical size of 4000x4000 voxels is
ans*4000=0.0096 %meters
i.e. less then 1 centimeter....

Barry Williams

unread,
Jul 31, 2012, 9:38:18 AM7/31/12
to
"Igor" wrote in message <jv8kji$og4$1...@newscl01ah.mathworks.com>...
Pardon me, obviously too early...

But we still go back and forth. So was this obtained with an IR microscope with software that relates dpi to the original physical size of the object? As I understand it, dpi in an image is referenced back to a the size of an image as printed or displayed and is essentially an invented number until it's associated with something displayed in some manner. Maybe someone with a better understanding of image processing will have a better answer.

Barry

Igor

unread,
Jul 31, 2012, 10:32:17 AM7/31/12
to

> Pardon me, obviously too early...
>
> But we still go back and forth.

As i understood, there's no documented (or at least 100% working) way to read jpg dpi)... That's a pity...

>So was this obtained with an IR microscope,with software that relates dpi to the original physical size of the object?

Not IR - it's X-ray, and not microscope - it's tomograph. But yes - DPI is related to original physical size, as it should.

Barry Williams

unread,
Jul 31, 2012, 10:45:14 AM7/31/12
to
"Igor" wrote in message <jv8q9h$j6c$1...@newscl01ah.mathworks.com>...
output=exifread('foo.jpg');

Interesting that there is a note associated with this function saying that it may be removed in a future release, since iminfo doesn't appear to grab some of the exif parameters.

Barry

Igor

unread,
Jul 31, 2012, 1:17:37 PM7/31/12
to
"Barry Williams" <barry.r.wil...@saic.com> wrote in message
> output=exifread('foo.jpg');

I've already tested it: no luck - it only returns 'UserComment' string. And it's how it should work- those XResolution/YResolution/ResolutionUnits properties are not a part of EXIF, AFAIK.

By the way, here's an example of such image:
http://img515.imageshack.us/img515/3536/dpitest.jpg
(i've erased the image itself, for it not to be too heavy).

Barry Williams

unread,
Jul 31, 2012, 1:37:43 PM7/31/12
to
"Igor" wrote in message <jv93vh$60$1...@newscl01ah.mathworks.com>...
Well, actually I had tried out exifread on a jpg from a digital camera and XResolution, YResolution and ResolutionUnits were specified as such and extracted from the file. Look at the following link:
http://www.metadataworkinggroup.org/pdf/mwg_guidance.pdf
Could the metadata file be in some format other than EXIF?
Barry

Igor

unread,
Jul 31, 2012, 2:39:15 PM7/31/12
to
"Barry Williams" <barry.r.wil...@saic.com> wrote in message

> Well, actually I had tried out exifread on a jpg from a digital camera and XResolution, YResolution and ResolutionUnits were specified as such and extracted from the file.

Matlab is able to read XResolution and etc from some jpg files, and is unable to read it from others (while windows is still able to do it).

In this case, it might be, matlab is unable to display Xresolution because of empty ResolutionUnits parameter... (while IrfanView,Photoshop,win7-properties and others are able to display this info)

> Could the metadata file be in some format other than EXIF?
Sure..
bmp is an example of a format without EXIF support at all, still it has HorzResolution property (see: http://stackoverflow.com/questions/9306766/reading-dpi-data-from-an-image-using-matlab)

John

unread,
Aug 2, 2012, 12:17:19 PM8/2/12
to
"Barry Williams" <barry.r.wil...@saic.com> wrote in message <jv9557$5br$1...@newscl01ah.mathworks.com>...
I believe you are correct. The (optional) APP1 segment of a JPEG file can contain Exif information, which might have resolution tags, while the (also optional) APP0 segment may contain what the JFIF standard refers to as "Xdensity" and "Ydensity" along with their units, and a very few other items. That might be what the original author of this thread was referring to? As y'all found out, IMFINFO returns APP1 Exif metadata, but not APP0 segment metadata, which is much more limited. Not hard to tease it out, though.

Igor

unread,
Aug 3, 2012, 9:33:12 AM8/3/12
to
"John " <com.wor...@evans.john> wrote in message <jve96f$t5$1...@newscl01ah.mathworks.com>...
> The (optional) APP1 segment of a JPEG file can contain Exif information, which might have resolution tags, while the (also optional) APP0 segment may contain what the JFIF standard refers to as "Xdensity" and "Ydensity" along with their units, and a very few other items. That might be what the original author of this thread was referring to? As y'all found out, IMFINFO returns APP1 Exif metadata, but not APP0 segment metadata, which is much more limited. Not hard to tease it out, though.

Thanks for the info, John!
Maybe I'll write something to read that info to matlab later. Not top priority for me now.
0 new messages