I'm rotating a picture the following way:
# 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
Why does the shape of the image not change?
Image augmentation does not change the actual or physical shape
of your image. Think of the original shape
as an window
from where you see the image or the outside world. Here all the transformations i.e., rotations
, stretchings
, translation
or in general any homography
or non-linear warps
are applied to the world outside your window. The opening from where you look at the image, in my analogy the window, stays the same irrespective how the world outside i.e., the image changes.
Now it can obviously bring in some other region, not present in the original view, to the augmented view. Most often, newly introduced pixels will be black or it may depend on what kind of padding
is applied.
In short, augmentation operations are not something like matrix transpose
where the actual shape may change.
img = cv2.imread("img.png")
augmentation = iaa.Affine(rotate=90)
img_aug = augmentation(image=img)
Let's see the images:
Original Image
Rotated Image