ChannelSwap
Targets:
image
Image Types:uint8, float32
Fixed channel reordering (e.g. RGB->BGR). Convenience subclass of ChannelShuffle with a
required channel_order argument.
Arguments
channel_ordertuple[int, ...]
[2,1,0]
Permutation of channel indices. Length must match image channels. For 3-channel, (2, 1, 0) swaps R and B (RGB->BGR). Default: (2, 1, 0).
pfloat
0.5
Probability of applying the transform. Default: 0.5.
Examples
>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>>
>>> # Swap R and B (RGB -> BGR)
>>> transform = A.ChannelSwap(channel_order=(2, 1, 0), p=1.0)
>>> result = transform(image=image)["image"]
>>> np.testing.assert_array_equal(result[:, :, 0], image[:, :, 2])Notes
- channel_order must be a permutation of 0..C-1 for C channels.
- (2, 1, 0) gives RGB->BGR; (0, 2, 1) swaps G and B.
See Also
- ChannelShuffle: Random permutation each call; use for invariance to channel order.