Which is the width and height dimension of imread result?

10 views (last 30 days)
Why cannot found this in the imread documentation? And also the direction is not specified, I think the convention differs from general coordinate system convention.
  2 Comments
Stephen23
Stephen23 on 18 Feb 2015
Edited: Stephen23 on 18 Feb 2015
According to your user profile you have asked sixteen questions, but not Accepted a single answer. It is considered polite on this forum to Accept an answer that best resolves your question.

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 18 Feb 2015
Edited: Stephen23 on 18 Feb 2015
The reason you cannot find any "unit" for the image is because there are none. Raster images are just collections of pixels, so that is what MATLAB imports with imread and all the other image importing functions: an array of the image pixel data. You can get the numbers of pixels (array elements) using the size function.
Contrary to what most people think, raster images do not have dimensions in units like mm or cm, although some image file formats store meta-data about image resolution (e.g. EXIF ), which then implicitly defines a "size" for that image. If you want to read this meta-data into MATLAB, then you can use iminfo .
If you have a good quality image manipulation program (such as GIMP), you can change an image's resolution and its size inverse-proportionally to one another, and yet the image pixels themselves stay unchanged. The resolution/dimensions are irrelevant information:
"The dpi-value in the EXIF is meaningless. It is a fictitious number. (A photo has no dpi, only pixels)"
You might like to read about image resolution too:
  2 Comments
Mr M.
Mr M. on 18 Feb 2015
Not the unit what is missing! You do not understand my question. My problem is that "M-by-N" is in the documentation, but no specification which is the height and which is the width of the image, and measured from left to right or right to left, and top to bottom or bottom to top?
Stephen23
Stephen23 on 18 Feb 2015
Edited: Stephen23 on 18 Feb 2015
This is much less complicated than you imagine: each row of pixels corresponds to one row of your data array, ditto for each column. The top of the image can be found at the top of the array, the bottom at the bottom.
There is no rotation, skewing, inversion, or any other conversion applied by imread.
MATLAB indexing is row first (as is standard in mathematics), so MxN mean M rows and N columns of data in a matrix. These correspond directly to the pixels of the image. You can get these values using the size function. Note also that images often have three dimensions, where the third dimension encodes each of the RGB channels.
And we can also demonstrate this very easily: I generated a small .PNG image of the letter A, shown here:
When I import this using imread, look at how the data array is displayed in the command window:

Sign in to comment.

More Answers (2)

garrett patton
garrett patton on 18 Feb 2015
I think reason of behind is Raster images are collections of pixels.

Image Analyst
Image Analyst on 18 Feb 2015
imread doesn't return the image size. You need to use size():
yourImage = imread(fullFileName);
[rows, columns, numberOfColorChannels] = size(yourImage);
Don't forget the third return argument, numberOfColorChannels, or you'll run into trouble. See http://blogs.mathworks.com/steve/2011/03/22/too-much-information-about-the-size-function/, Steve's blog for more information. Steve is the leader of the imaging group at the Mathworks.

Community Treasure Hunt

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

Start Hunting!