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

2024-06-11 07:34:59 发布

您现在位置:Python中文网/ 问答频道 /正文

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

# 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

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


Tags: imageimgread方式图片widthaugprint
1条回答
网友
1楼 · 发布于 2024-06-11 07:34:59

图像增强不会改变图像的实际或物理shape。把原始的shape想象成一个window,从那里你可以看到图像或外部世界。在这里,所有的转换,即rotationsstretchingstranslation或通常的任何homography或非线性warps都应用于窗口外的世界。在我的类比中,从你看图像的那个窗口,无论外面的世界如何变化,也就是图像如何变化,都保持不变

现在,它显然可以将原始视图中不存在的其他区域引入到增强视图中。最常见的情况是,新引入的像素将是黑色的,或者它可能取决于应用了什么类型的padding

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

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

让我们看看图片:

Original Image

enter image description here

Rotated Image

enter image description here

相关问题 更多 >