0
$\begingroup$

enter image description here

I am using this python code to read this image file

image = img.imread('/content/drive/My Drive/Colab Notebooks/rusty.png')

How do I determine the dimension of this image array? I printed out len(image), len(image[0]) and len(image[0][0]) Which probably shows what's the len of each submatrix...

$\endgroup$
2
  • $\begingroup$ Hello joseph, what librairie are you using for img.imread, is it openCV (cv2) or matplotlib.pyplot ? In either ways if your variable image is a numpy array (which is very likely and checkable by printing type(image)), you can just print image.shape to get the size of the image (height, width, channels) $\endgroup$
    – Ubikuity
    Jul 28 at 19:05
  • $\begingroup$ import matplotlib.image as img $\endgroup$
    – joseph
    Jul 28 at 19:12
0
$\begingroup$

Use shape to find the dimensions of an object Reference link

image.shape

images are stored in numpy ndarray. To get the image shape or size, use ndarray.shape to get the dimensions of the image. Then, you can use index on the dimensions variable to get width, height and number of channels for each pixel.

$\endgroup$
0
0
$\begingroup$

convert list to nparray:

import numpy as np

image=np.array(image) 
print(image.shape)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.