9

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?

Joseph
  • 2,706
  • 6
  • 42
  • 80

6 Answers6

18

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.

sdye1991
  • 181
  • 1
  • 7
11

Is it possible that you have defined a variable named size before this code?

3lectrologos
  • 9,469
  • 4
  • 39
  • 46
3

You must use [height, width, colour_planes] = size(image); because images have 3 dimensions. The third dimension is the number of colour planes. If you don't need this value, you can substitute ~ to ignore it.

Alexander
  • 59,041
  • 12
  • 98
  • 151
KyungHoon Kim
  • 2,859
  • 2
  • 23
  • 26
1

Just use this whos and press enter.

image=imread('text.jpg');
whos
Nazik
  • 8,696
  • 27
  • 77
  • 123
1

[x,y,z]=size(image); is the correct one. x and y will give length and breadth of the image and z specifies color.

Digital image consists of RGB so z will be 3.

Sndn
  • 980
  • 12
  • 20
-3

You can try this:

image=imread('text.jpg');
[x y]=size(image);
Seth Malaki
  • 4,436
  • 23
  • 48
Fooz
  • 1