Transpose
Targets:
image
mask
bboxes
keypoints
volume
mask3d
Image Types:uint8, float32
Transpose the input by swapping its rows and columns.
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.
Arguments
pfloat
0.5
Probability of applying the transform. Default: 0.5.
Examples
>>> 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"]Notes
- The dimensions of the output will be swapped compared to the input. For example, an input image of shape (100, 200, 3) will result in an output of shape (200, 100, 3).
- This transform is self-inverse: applying it twice returns the original image.
Call
inverse()to get a new instance that undoes the transpose (identical to applying it again), useful for TTA pipelines. - For multi-channel images (like RGB), the channels are preserved in their original order.
- Bounding boxes will have their coordinates adjusted to match the new image dimensions.
- Keypoints will have their x and y coordinates swapped.