In [1]:
import cv2

In [2]:
im = cv2.imread('data/src/lena.jpg')

In [3]:
print(type(im))


<class 'numpy.ndarray'>

In [4]:
print(im.shape)
print(type(im.shape))


(225, 400, 3)
<class 'tuple'>

In [5]:
h, w, c = im.shape
print('width:  ', w)
print('height: ', h)
print('channel:', c)


width:   400
height:  225
channel: 3

In [6]:
h, w, _ = im.shape
print('width: ', w)
print('height:', h)


width:  400
height: 225

In [7]:
print('width: ', im.shape[1])
print('height:', im.shape[0])


width:  400
height: 225

In [8]:
print(im.shape[1::-1])


(400, 225)

In [9]:
im_gray = cv2.imread('data/src/lena.jpg', cv2.IMREAD_GRAYSCALE)

In [10]:
print(im_gray.shape)
print(type(im_gray.shape))


(225, 400)
<class 'tuple'>

In [11]:
h, w = im_gray.shape
print('width: ', w)
print('height:', h)


width:  400
height: 225

In [12]:
print('width: ', im_gray.shape[1])
print('height:', im_gray.shape[0])


width:  400
height: 225

In [13]:
h, w = im.shape[0], im.shape[1]
print('width: ', w)
print('height:', h)


width:  400
height: 225

In [14]:
print(im_gray.shape[::-1])
print(im_gray.shape[1::-1])


(400, 225)
(400, 225)