我有一张72x96的照片。Windows说它的尺寸是72x96。PIL图像还显示它是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)
但是当我用cv2.imread
或skimage.io.imread
阅读图像时,它说,图像的形状是(96, 72, 3)
:
from skimage.io import imread
im0 = imread(<path>)
print(im0.shape) # (96, 72, 3)
这里怎么了?即使我做了这样的事:
import matplotlib.pyplot as plt
plt.imshow(im0)
它以正确的大小显示图像,但写入的大小看起来被转置了
这是预期的行为
PIL将图像的大小返回为(宽度,高度)(PIL documentation),而numpy将数组的形状返回为第一维和第二维的长度(对于二维数组),因此(高度,宽度)(Numpy documentation)
相关问题 更多 >
编程相关推荐