ChannelSwap

Targets:
image
volume
Image Types:uint8, float32

Apply a fixed channel reordering to the image.

Unlike ChannelShuffle which randomly permutes channels each time, ChannelSwap applies a deterministic, user-specified channel order. Useful for BGR<->RGB conversion, or for training models that should be invariant to a specific channel ordering.

Arguments
channel_order
tuple[int, ...]
[2,1,0]

Target channel order as a tuple of indices. For a 3-channel image, (2, 1, 0) swaps R and B (RGB->BGR). Default: (2, 1, 0).

p
float
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 channels (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])