Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab size of image

Tags:

matlab

I am trying to find the size of an image I have loaded into matlab.

image=imread('text.jpg');
[x,y]=size(image);

This return the error:

Indexing cannot yield multiple results.

Does imread not read the image into a 2d array, which should therefore have two sizes?

like image 320
Joseph Avatar asked Mar 04 '12 12:03

Joseph


1 Answers

For those looking to find the size of an image in matlab, don't use:

[height, width] = size(image);

This is because imread stores the RGB values separately (for colour images), resulting in a three dimensional matrix.

For example, if you loaded a 500p high, 200p wide colour image, this would result in a 500x200x3 matrix.

Calling size() in this way would result in the dimensionality being 'rolled up', and would report the height to be 500, but the width to be 600 (200 * 3).

Instead, using:

[height, width, dim] = size(image);

would return correct values of 500, 200, 3.

like image 85
sdye1991 Avatar answered Sep 30 '22 05:09

sdye1991