4

I need to get width and height of an image using imageio, loading an image into imageio with imread, how can I get the height and width of the image or in another word the resolution of the image? in the documentation, it mentions it will return numpy array

example:

>>> from imageio import imread
>>> image_date = imread('c:/myImage.png')

when I print it out, I believe it returns a list of array of color

>>> print image_date
[[[ 18  23  16]
  [ 31  32  24]
  [ 34  29  23]
  ..., 
  [ 97  73  49]
  [ 95  73  50]
  [ 94  72  49]]

 [[ 23  24  18]
  [ 30  30  22]
  [ 36  29  21]
  ..., 
  [ 98  74  50]
  [ 95  73  50]
  [ 95  73  50]]

 [[ 32  27  21]
  [ 34  29  23]
  [ 37  28  21]
  ..., 
  [ 94  72  48]
  [ 97  72  50]
  [ 97  72  50]]

 ..., 
 [[ 43  35  24]
  [ 46  36  26]
  [ 48  36  24]
  ..., 
  [ 47  31  18]
  [ 47  31  18]
  [ 47  30  20]]

 [[ 59  56  47]
  [ 59  55  46]
  [ 59  50  41]
  ..., 
  [ 49  33  20]
  [ 48  32  19]
  [ 48  32  19]]

 [[114 115 107]
  [104 104  96]
  [100  93  85]
  ..., 
  [ 48  32  19]
  [ 48  32  19]
  [ 47  31  18]]]

any idea? thanks in advance.

Bear
  • 550
  • 9
  • 25

1 Answers1

9

image_date is a numpy array so you can use the shape attribute. For example:

$ file black.png
black.png: PNG image data, 700 x 450, 8-bit/color RGB, non-interlaced

So black.png is a image with a width of 700 pixels and a height of 450 pixels. Then in Python:

imageio.imread('black.png').shape

Outputs:

(450, 700, 3)
Jacques Kvam
  • 2,856
  • 1
  • 26
  • 31
  • I see... that works!! so it means in your example there is an array of 3 (RGB) in each cell of width array and each width array is in each cell of height array or in another word imageio read image from top left to bottom right correct? – Bear Apr 17 '18 at 09:12
  • Yes, the numpy array is 3 dimensional, first being the height, second is the width, and third are the RGB channels. – Jacques Kvam Apr 17 '18 at 18:14