使用 imgaug 旋转后图像的形状不会改变

Shape of image does not change after rotation with imgaug

我正在按以下方式旋转图片:

# Read in image
img = cv2.imread("pic.jpg")
height, width, _ = img.shape
print("height ", height)
print("width ", width)

# Rotate image by 90 degrees
augmentation = iaa.Affine(rotate=90)
img_aug = augmentation(image=img)

height, width, _ = img_aug.shape
print("Height after rotation ", height)
print("Width after rotation ", width

> height  1080
> width  1920
> Height after rotation  1080
> Width after rotation  1920

为什么图像的形状没有改变?

图像增强不会改变图像的实际或物理 shape。将原始 shape 想象成一个 window,从那里你可以看到图像或外部世界。这里所有的转换,即 rotationsstretchingstranslation 或一般的任何 homography 或 non-linear warps 都应用于你之外的世界window。从你看图像的地方开始,在我的类比中 window,无论外面的世界如何变化,即图像如何变化,都保持不变。

现在它显然可以将原始视图中不存在的其他区域引入增强视图。大多数情况下,新引入的像素将是黑色的,或者可能取决于应用了哪种 padding

简而言之,扩充操作不像矩阵 transpose 那样实际形状可能会发生变化。

img = cv2.imread("img.png")
augmentation = iaa.Affine(rotate=90)
img_aug = augmentation(image=img)

让我们看看图片:

Original Image

Rotated Image