← Back to all transforms
ToRGB
Description
Convert an input image from grayscale to RGB format. Args: num_output_channels (int): The number of channels in the output image. Default: 3. p (float): Probability of applying the transform. Default: 1.0. Targets: image Image types: uint8, float32 Number of channels: 1 Note: - 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). Raises: TypeError: If the input image has more than 1 channel. 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)
Parameters
- num_output_channels: int (default: 3)
- p: float (default: 1)
Targets
- Image
Try it out
ⓘ
Original Image:
Result:
Transform result will appear here