ToRGB
Convert an input image from grayscale to RGB format.
Supported Targets
image
Arguments
NameTypeDefaultDescription
num_output_channels
int
The number of channels in the output image. Default: 3.
p
float
Probability of applying the transform. Default: 1.0.
Image Types
uint8, float32
Notes
- For single-channel (grayscale) images, the channel is replicated to create an RGB image. - If the input is already a 3-channel RGB image, it is returned unchanged. - This transform does not change the data type of the image (e.g., uint8 remains uint8).
Examples
>>> import numpy as np
>>> import albumentations as A
>>>
>>> # Convert a grayscale image to RGB
>>> transform = A.Compose([A.ToRGB(p=1.0)])
>>> grayscale_image = np.random.randint(0, 256, (100, 100), dtype=np.uint8)
>>> rgb_image = transform(image=grayscale_image)['image']
>>> assert rgb_image.shape == (100, 100, 3)