Search code examples
imagematlabresolution

Getting image resolution in matlab


I am working on a project where I need to find image resolution for an image or any relation between image height and width with the resolution of image.

When we right click on an image and select properties->details, we have the resolution information.

How can we extract that information in matlab?

Is that information does not depend on image properties because somewhere I read image has only pixel information, ppi or dpi depends on printer, sensors.


Solution

  • You can use imfinfo matlab function, which returns a structure whose fields contain information about the image.

    For example:

    info = imfinfo(YOUR_IMAGE);
    w = info.Width;  %An integer indicating the width of the image in pixels
    h = info.Height; %An integer indicating the height of the image in pixels
    

    In your case, you probably want to get: Horizontal resolution and Vertical resolution. So use:

    xR = info.XResolution
    yR = info.YResolution
    

    For more information: http://www.mathworks.com/help/matlab/ref/imfinfo.html