RGB#
rgb_to_bgr() reverses the channels. rgb_to_rgb255() and rgb255_to_rgb() scale between
\([0, 1]\) and \([0, 255]\). normals_to_rgb255() and rgb255_to_normals() map surface normals between
\([-1, 1]\) and \([0, 255]\) colours.
Tip
Learn more: https://en.wikipedia.org/wiki/RGB_color_model
Functions#
- kornia.color.rgb_to_bgr(image)[source]#
Convert an RGB image to BGR.
bgr = rgb_to_bgr(image)reorders the channels of a(*, 3, H, W)RGB image to BGR, the order OpenCV uses.
- Convention:
Reverses the three channels at axis -3; it is its own inverse.
- Parameters:
image (
Tensor) – RGB image with shape(*, 3, H, W).- Return type:
- Returns:
BGR image with shape
(*, 3, H, W).
See also
bgr_to_rgb(): the same operation under the other name.RgbToBgr: the module form.
Example
>>> input = torch.rand(2, 3, 4, 5) >>> output = rgb_to_bgr(input) # 2x3x4x5
- kornia.color.rgb_to_rgb255(image)[source]#
Scale an RGB image from [0, 1] to [0, 255].
out = rgb_to_rgb255(image)multiplies a(*, 3, H, W)unit-range RGB image by 255. The result is a float image, not uint8.- Convention:
Values are clamped to \([0, 255]\) and not rounded.
- Parameters:
image (
Tensor) – RGB image with shape(*, 3, H, W).- Return type:
- Returns:
RGB image in \([0, 255]\) with shape
(*, 3, H, W).
See also
rgb255_to_rgb(): divides by 255 and does not clip.RgbToRgb255: the module form.
Example
>>> input = torch.rand(2, 3, 4, 5) >>> output = rgb_to_rgb255(input) # 2x3x4x5
- kornia.color.rgb255_to_rgb(image)[source]#
Scale an RGB image from [0, 255] to [0, 1].
out = rgb255_to_rgb(image)divides a(*, 3, H, W)image in \([0, 255]\) by 255.- Convention:
Values outside \([0, 255]\) are not clipped.
- Parameters:
image (
Tensor) – RGB image in \([0, 255]\) with shape(*, 3, H, W).- Return type:
- Returns:
RGB image in \([0, 1]\) with shape
(*, 3, H, W).
See also
rgb_to_rgb255(): multiplies by 255 and clamps.Rgb255ToRgb: the module form.
Example
>>> input = torch.rand(2, 3, 4, 5) >>> output = rgb255_to_rgb(input) # 2x3x4x5
- kornia.color.rgb255_to_normals(image)[source]#
Map an RGB image in [0, 255] to unit surface normals.
normals = rgb255_to_normals(image)maps each channelcof a(*, 3, H, W)image to2 * c / 255 - 1and scales every pixel’s three components to unit length.- Convention:
A pixel that maps to the zero vector, such as mid grey (127.5, 127.5, 127.5), stays zero.
Half inputs are computed in float32 and rounded to the input dtype once at return.
- Parameters:
image (
Tensor) – RGB image in \([0, 255]\) with shape(*, 3, H, W).- Return type:
- Returns:
Surface normals with shape
(*, 3, H, W).
See also
normals_to_rgb255(): the inverse for unit-length normals; it does not normalize.Rgb255ToNormals: the module form.
Example
>>> input = torch.rand(2, 3, 4, 5) >>> output = rgb255_to_normals(input) # 2x3x4x5
- kornia.color.normals_to_rgb255(image)[source]#
Map surface normals in [-1, 1] to RGB in [0, 255].
rgb = normals_to_rgb255(image)maps each componentnof a(*, 3, H, W)normal map to255 * (n + 1) / 2, so -1, 0 and 1 become 0, 127.5 and 255.- Convention:
Components outside \([-1, 1]\) are clamped; the vectors are not normalized.
- Parameters:
image (
Tensor) – surface normals with shape(*, 3, H, W).- Return type:
- Returns:
RGB image in \([0, 255]\) with shape
(*, 3, H, W).
See also
rgb255_to_normals(): the inverse for unit-length normals.NormalsToRgb255: the module form.
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 (module form).
out = RgbToBgr()(image)isrgb_to_bgr().- Shape:
image:
(*, 3, H, W)output:
(*, 3, H, W)
See also
rgb_to_bgr(): the one-call form.BgrToRgb: the same channel reversal.
Example
>>> input = torch.rand(2, 3, 4, 5) >>> bgr = RgbToBgr() >>> output = bgr(input) # 2x3x4x5
- class kornia.color.RgbToRgb255(*args, **kwargs)[source]#
Scale an RGB image from [0, 1] to [0, 255] (module form).
out = RgbToRgb255()(image)isrgb_to_rgb255().- Convention:
See the convention block of
rgb_to_rgb255().
- Shape:
image:
(*, 3, H, W)output:
(*, 3, H, W)
See also
rgb_to_rgb255(): the one-call form.Rgb255ToRgb: divides by 255.
Example
>>> input = torch.rand(2, 3, 4, 5) >>> rgb = RgbToRgb255() >>> output = rgb(input) # 2x3x4x5
- class kornia.color.Rgb255ToRgb(*args, **kwargs)[source]#
Scale an RGB image from [0, 255] to [0, 1] (module form).
out = Rgb255ToRgb()(image)isrgb255_to_rgb().- Convention:
See the convention block of
rgb255_to_rgb().
- Shape:
image:
(*, 3, H, W)output:
(*, 3, H, W)
See also
rgb255_to_rgb(): the one-call form.RgbToRgb255: multiplies by 255.
Example
>>> input = torch.rand(2, 3, 4, 5) >>> rgb = Rgb255ToRgb() >>> output = rgb(input) # 2x3x4x5
- class kornia.color.Rgb255ToNormals(*args, **kwargs)[source]#
Map an RGB image in [0, 255] to unit surface normals (module form).
out = Rgb255ToNormals()(image)isrgb255_to_normals().- Convention:
See the convention block of
rgb255_to_normals().
- Shape:
image:
(*, 3, H, W)output:
(*, 3, H, W)
See also
rgb255_to_normals(): the one-call form.NormalsToRgb255: maps normals to colors.
Example
>>> input = torch.rand(2, 3, 4, 5) >>> normals = Rgb255ToNormals() >>> output = normals(input) # 2x3x4x5
- class kornia.color.NormalsToRgb255(*args, **kwargs)[source]#
Map surface normals in [-1, 1] to RGB in [0, 255] (module form).
out = NormalsToRgb255()(image)isnormals_to_rgb255().- Convention:
See the convention block of
normals_to_rgb255().
- Shape:
image:
(*, 3, H, W)output:
(*, 3, H, W)
See also
normals_to_rgb255(): the one-call form.Rgb255ToNormals: the inverse for unit-length normals.
Example
>>> input = torch.rand(2, 3, 4, 5) >>> rgb = NormalsToRgb255() >>> output = rgb(input) # 2x3x4x5