ChannelShuffle

Targets:
image
volume
Image Types:uint8, float32

Randomly rearrange channels of the image.

Arguments
p
float
0.5

Probability of applying the transform. Default: 0.5.

Examples
>>> import numpy as np
>>> import albumentations as A
>>>
>>> # Create a sample image with distinct RGB channels
>>> image = np.zeros((100, 100, 3), dtype=np.uint8)
>>> # Red channel (first channel)
>>> image[:, :, 0] = np.linspace(0, 255, 100, dtype=np.uint8).reshape(1, 100)
>>> # Green channel (second channel)
>>> image[:, :, 1] = np.linspace(0, 255, 100, dtype=np.uint8).reshape(100, 1)
>>> # Blue channel (third channel) - constant value
>>> image[:, :, 2] = 128
>>>
>>> # Apply channel shuffle transform
>>> transform = A.ChannelShuffle(p=1.0)
>>> result = transform(image=image)
>>> shuffled_image = result['image']
>>>
>>> # The channels have been randomly rearranged
>>> # For example, the original order [R, G, B] might become [G, B, R] or [B, R, G]
>>> # This results in a color shift while preserving all the original image data
>>> # Note: For images with more than 3 channels, all channels are shuffled similarly