ImageIO - get image Width and Height from loaded image

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.

1 answer

  • answered 2018-04-17 04:57 Jacques Kvam

    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)