Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

How can i get the dpi of an image

Hi,  there's a way to obtain the resolution (dpi or pixels/mm) of an image (jpg, bmp or png) in labview with or without the Vision Development Module?
thanks in advance
0 Kudos
Message 1 of 3
(4,203 Views)

Hi, Amx,

You should understand how the resolution info stored in the images.
In general, this info stored in metadata inside of the image file (mostly in header) and depends from the image format. Jpeg, tiff, png stores this info in different ways.

For example, inside of png format with 300dpi this info stored by following way:
First, four bytes (hexadecimal): 70 48 59 73
Then resolution in pixels per meter 00 00 2E 2D 00 00 2E 2D
Finally one byte 01 (unit specifier defined)
So, your resolution calculated by following 2E 2D (hex) = 11821 pixels in meter; it means 118.21 pixel per cm; it means 118.21 * 2.54 = 300 pixel per inch.

In jpeg or tiff this info will be stored by other way.
There are no way for recover this info with or without VDM. You should parse the hader of the file (yourself, or, may be with third party library). If you will try to open calibrated image with IMAQ Vision functions, and then check calibration info, then you will get an error -1074396113 ( The source/input image has not been calibrated.)

Otherwise IMAQ Image can be calibrated, but do not mix IMAQ Vision calibration with calibration described above. NI uses own calibration info, which can be stored in png (with vision info) or aipd files.

Resume. If you need to open "third party" calibrated files in your application (stored in Photoshop, for example), then you need to have appropriate parser for header for recovering this info. But if you have Vision Development Module and want to save calibration info in your own files, then you can use IMAQ Write Image And Vision Info  / IMAQ Read Image And Vision Info functions for this task.

hopefully it helps,
Andrey.

Message 2 of 3
(4,176 Views)
Thanks Andrey, I know a little about headers but i was looking for a simplest way to do that.
0 Kudos
Message 3 of 3
(4,148 Views)