RGB#
Tip
Learn more: https://en.wikipedia.org/wiki/RGB_color_model
Functions#
- kornia.color.rgb_to_bgr(image)[source]#
Convert a RGB image to BGR.
- Convention:
Reverses the three channels at axis -3; leading dimensions are preserved.
- Parameters:
image (
Tensor) – RGB Image to be converted to BGRof of shape \((*,3,H,W)\).- Return type:
- Returns:
BGR version of the image with shape of shape \((*,3,H,W)\).
Example
>>> input = torch.rand(2, 3, 4, 5) >>> output = rgb_to_bgr(input) # 2x3x4x5
- kornia.color.rgb_to_rgb255(image)[source]#
Convert an image from RGB to RGB [0, 255] for visualization purposes.
- Convention:
Multiplies unit-range RGB values by 255 and clamps the result to [0, 255].
- Parameters:
image (
Tensor) – RGB Image to be converted to RGB [0, 255] of shape \((*,3,H,W)\).- Return type:
- Returns:
RGB version of the image with shape of shape \((*,3,H,W)\).
Example
>>> input = torch.rand(2, 3, 4, 5) >>> output = rgb_to_rgb255(input) # 2x3x4x5
- kornia.color.rgb255_to_rgb(image)[source]#
Convert an image from RGB [0, 255] to RGB for visualization purposes.
- Convention:
Divides RGB255 values by 255 without clipping.
- Parameters:
image (
Tensor) – RGB Image to be converted to RGB of shape \((*,3,H,W)\).- Return type:
- Returns:
RGB version of the image with shape of shape \((*,3,H,W)\).
Example
>>> input = torch.rand(2, 3, 4, 5) >>> output = rgb255_to_rgb(input) # 2x3x4x5
- kornia.color.rgb255_to_normals(image)[source]#
Convert an image from RGB [0, 255] to surface normals for visualization purposes.
- Convention:
Maps RGB255 channels to [-1, 1], then normalizes each three-channel vector at axis -3. Half inputs are computed in float32 and rounded to the input dtype once at return.
- Parameters:
image (
Tensor) – RGB Image to be converted to surface normals of shape \((*,3,H,W)\).- Return type:
- Returns:
surface normals version of the image with shape of shape \((*,3,H,W)\).
Example
>>> input = torch.rand(2, 3, 4, 5) >>> output = rgb255_to_normals(input) # 2x3x4x5
- kornia.color.normals_to_rgb255(image)[source]#
Convert surface normals to RGB [0, 255] for visualization purposes.
- Convention:
Maps normal components from [-1, 1] to RGB255 channels [0, 255], clamping the result.
- Parameters:
image (
Tensor) – surface normals to be converted to RGB with quantization of shape \((*,3,H,W)\).- Return type:
- Returns:
RGB version of the image with shape of shape \((*,3,H,W)\).
Example
>>> input = torch.rand(2, 3, 4, 5) >>> output = normals_to_rgb255(input) # 2x3x4x5
Modules#
- class kornia.color.RgbToBgr(*args, **kwargs)[source]#
Convert an image from RGB to BGR.
See the Convention block on
rgb_to_bgr().The image data is assumed to be in the range of (0, 1).
- Returns:
BGR version of the image.
- Shape:
image: \((*, 3, H, W)\)
output: \((*, 3, H, W)\)
Example
>>> input = torch.rand(2, 3, 4, 5) >>> bgr = RgbToBgr() >>> output = bgr(input) # 2x3x4x5
- class kornia.color.RgbToRgb255(*args, **kwargs)[source]#
Convert an image from RGB to RGB [0, 255] for visualization purposes.
See the Convention block on
rgb_to_rgb255().- Returns:
RGB version of the image.
- Shape:
image: \((*, 3, H, W)\)
output: \((*, 3, H, W)\)
Example
>>> input = torch.rand(2, 3, 4, 5) >>> rgb = RgbToRgb255() >>> output = rgb(input) # 2x3x4x5
- class kornia.color.Rgb255ToRgb(*args, **kwargs)[source]#
Convert an image from RGB [0, 255] to RGB for visualization purposes.
See the Convention block on
rgb255_to_rgb().- Returns:
RGB version of the image.
- Shape:
image: \((*, 3, H, W)\)
output: \((*, 3, H, W)\)
Example
>>> input = torch.rand(2, 3, 4, 5) >>> rgb = Rgb255ToRgb() >>> output = rgb(input) # 2x3x4x5
- class kornia.color.Rgb255ToNormals(*args, **kwargs)[source]#
Convert an image from RGB [0, 255] to surface normals for visualization purposes.
See the Convention block on
rgb255_to_normals().- Returns:
surface normals version of the image.
- Shape:
image: \((*, 3, H, W)\)
output: \((*, 3, H, W)\)
Example
>>> input = torch.rand(2, 3, 4, 5) >>> normals = Rgb255ToNormals() >>> output = normals(input) # 2x3x4x5
- class kornia.color.NormalsToRgb255(*args, **kwargs)[source]#
Convert surface normals to RGB [0, 255] for visualization purposes.
See the Convention block on
normals_to_rgb255().- Returns:
RGB version of the image.
- Shape:
image: \((*, 3, H, W)\)
output: \((*, 3, H, W)\)
Example
>>> input = torch.rand(2, 3, 4, 5) >>> rgb = NormalsToRgb255() >>> output = rgb(input) # 2x3x4x5