Transpose by swapping rows and columns (width/height swap). Supports image, mask, bboxes, keypoints, volume. Self-inverse; use inverse() for TTA.
This transform flips the image over its main diagonal, effectively switching its width and height. It's equivalent to a 90-degree rotation followed by a horizontal flip.
pProbability of applying the transform. Default: 0.5.
>>> import numpy as np
>>> import albumentations as A
>>> image = np.array([
... [[1, 2, 3], [4, 5, 6]],
... [[7, 8, 9], [10, 11, 12]]
... ])
>>> transform = A.Transpose(p=1.0)
>>> result = transform(image=image)
>>> transposed_image = result['image']
>>> print(transposed_image)
[[[ 1 2 3]
[ 7 8 9]]
[[ 4 5 6]
[10 11 12]]]
# The original 2x2x3 image is now 2x2x3, with rows and columns swapped
>>> # TTA: transpose, run inference, un-transpose the predicted mask
>>> aug = A.Transpose(p=1)
>>> aug_image = aug(image=image)["image"]
>>> pred_mask = np.zeros((aug_image.shape[0], aug_image.shape[1], 1), dtype=np.uint8)
>>> restored_mask = aug.inverse()(image=pred_mask)["image"]inverse() to get a new instance that undoes the transpose (identical to
applying it again), useful for TTA pipelines.