albumentations.augmentations.pixel.channel
Permute image channels. By default the permutation is random (uniform over all orderings); set `channel_order` to pin a fixed reordering.
Members
- classChannelShuffle
- classChannelSwap
ChannelShuffleclass
ChannelShuffle(
channel_order: tuple[int, ...] | None,
p: float = 0.5
)Permute image channels. By default the permutation is random (uniform over all orderings); set `channel_order` to pin a fixed reordering.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| channel_order | One of:
| - | Fixed permutation of channel indices. When `None` (default), a random permutation is sampled each call. When a tuple, that exact order is applied every time (length must match the number of image channels). Default: None. |
| 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)
>>>
>>> # Random shuffle (default)
>>> transform = A.ChannelShuffle(p=1.0)
>>> result = transform(image=image)["image"]
>>>
>>> # Fixed reorder: RGB → BGR
>>> transform = A.ChannelShuffle(channel_order=(2, 1, 0), p=1.0)
>>> result = transform(image=image)["image"]Notes
- When `channel_order` is `None`, the permutation is chosen uniformly over all channel orderings; the same image can get different orderings on different calls. - When `channel_order` is set, the transform behaves deterministically (same as `ChannelSwap`).
ChannelSwapclass
ChannelSwap(
channel_order: tuple[int, ...] = (2, 1, 0),
p: float = 0.5
)Fixed channel reordering (e.g. RGB->BGR). Convenience subclass of `ChannelShuffle` with a required `channel_order` argument.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| channel_order | tuple[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). |
| 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 (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.