RGBA#
Tip
Learn more: https://en.wikipedia.org/wiki/RGBA_color_model
Functions#
- kornia.color.rgb_to_rgba(image, alpha_val)[source]#
Convert an image from RGB to RGBA.
- Parameters:
image (
Tensor) – RGB Image to be converted to RGBA of shape \((*,3,H,W)\).alpha_val (float, torch.Tensor) – A float number for the alpha value or a torch.tensor of shape \((*,1,H,W)\).
- Return type:
- Returns:
RGBA version of the image with shape \((*,4,H,W)\).
Note
The current functionality is NOT supported by Torchscript.
Example
>>> input = torch.rand(2, 3, 4, 5) >>> output = rgb_to_rgba(input, 1.) # 2x4x4x5
- kornia.color.rgba_to_rgb(image, background_color=None)[source]#
Convert an image from RGBA to RGB using alpha compositing.
The function composites the input RGBA image over a background color. If no background color is provided, it defaults to a white background.
- Parameters:
image (
Tensor) – The RGBA image to be converted, with shape \((*,4,H,W)\).background_color (
Optional[Tensor], optional) – An optional background color. It can be a tuple or list of 3 floats, a torch.Tensor of shape \((*,3,H,W)\) for a per-pixel background, or a broadcastable torch.Tensor (e.g., \((*,3,1,1)\)). If None, a white background is used. Default:None
- Return type:
- Returns:
The converted RGB image with shape \((*,3,H,W)\).
Example
>>> rgba_image = torch.rand(2, 4, 32, 32) >>> # Test with default white background >>> rgb_image_default = rgba_to_rgb(rgba_image) # 2x3x32x32 >>> # Test with a custom background color >>> rgb_image_custom = rgba_to_rgb(rgba_image, background_color=(0.0, 0.0, 1.0)) # 2x3x32x32
- kornia.color.rgba_to_bgr(image)[source]#
Convert an image from RGBA to BGR.
- Parameters:
image (
Tensor) – RGBA Image to be converted to BGR of shape \((*,4,H,W)\).- Return type:
- Returns:
RGB version of the image with shape \((*,3,H,W)\).
Example
>>> input = torch.rand(2, 4, 4, 5) >>> output = rgba_to_bgr(input) # 2x3x4x5
Modules#
- class kornia.color.RgbToRgba(alpha_val)[source]#
Convert an image from RGB to RGBA.
Add an alpha channel to existing RGB image.
- Parameters:
alpha_val (
Union[float,Tensor]) – A float number for the alpha value or a torch.Tensor of shape \((*,1,H,W)\).- Returns:
RGBA version of the image with shape \((*,4,H,W)\).
- Return type:
- Shape:
image: \((*, 3, H, W)\)
output: \((*, 4, H, W)\)
Note
The current functionality is NOT supported by Torchscript.
Example
>>> input = torch.rand(2, 3, 4, 5) >>> rgba = RgbToRgba(1.) >>> output = rgba(input) # 2x4x4x5
- class kornia.color.RgbaToRgb(*args, **kwargs)[source]#
Convert an image from RGBA to RGB.
Remove an alpha channel from RGB image.
- Returns:
RGB version of the image.
- Shape:
image: \((*, 4, H, W)\)
output: \((*, 3, H, W)\)
Example
>>> input = torch.rand(2, 4, 4, 5) >>> rgba = RgbaToRgb() >>> output = rgba(input) # 2x3x4x5
- class kornia.color.RgbaToBgr(*args, **kwargs)[source]#
Convert an image from RGBA to BGR.
Remove an alpha channel from BGR image.
- Returns:
BGR version of the image.
- Shape:
image: \((*, 4, H, W)\)
output: \((*, 3, H, W)\)
Example
>>> input = torch.rand(2, 4, 4, 5) >>> rgba = RgbaToBgr() >>> output = rgba(input) # 2x3x4x5