I have an image of size 72x96. Windows says its size is 72x96. PIL Image also says it is 72x96:
from PIL import Image, ImageOps
with Image.open(<path>) as img:
print(img.size) # (72, 96)
print(ImageOps.exif_transpose(img).size) # (72, 96)
But when I read the image with cv2.imread
or skimage.io.imread
it says, that the shape of the image is (96, 72, 3)
:
from skimage.io import imread
im0 = imread(<path>)
print(im0.shape) # (96, 72, 3)
What is wrong here? Even if I do something like that:
import matplotlib.pyplot as plt
plt.imshow(im0)
It shows the image with the correct size, but the written size looks to be transposed.
This is expected behavior.
PIL returns the size of an image as (width, height) (PIL documentation), whereas numpy returns the shape of an array as the lengths of the first and then second dimension (in the case of a 2d array), so (height, width) (Numpy documentation).