CIE Lab#

Functions#

kornia.color.rgb_to_lab(image)[source]#

Convert a RGB image to Lab.

_images/rgb_to_lab.png

The input RGB image is assumed to be in the range of \([0, 1]\). Lab color is computed using the D65 illuminant and Observer 2.

Parameters:

image (Tensor) – RGB Image to be converted to Lab with shape \((*, 3, H, W)\).

Return type:

Tensor

Returns:

Lab version of the image with shape \((*, 3, H, W)\). The L channel values are in the range 0..100. a and b are in the range -128..127.

Example

>>> input = torch.rand(2, 3, 4, 5)
>>> output = rgb_to_lab(input)  # 2x3x4x5
kornia.color.lab_to_rgb(image, clip=True)[source]#

Convert a Lab image to RGB.

The L channel is assumed to be in the range of \([0, 100]\). a and b channels are in the range of \([-128, 127]\).

Parameters:
  • image (Tensor) – Lab image to be converted to RGB with shape \((*, 3, H, W)\).

  • clip (bool, optional) – Whether to apply clipping to insure output RGB values in range \([0, 1]\). Default: True

Return type:

Tensor

Returns:

Lab version of the image with shape \((*, 3, H, W)\). The output RGB image are in the range of \([0, 1]\).

Example

>>> input = torch.rand(2, 3, 4, 5)
>>> output = lab_to_rgb(input)  # 2x3x4x5

Modules#

class kornia.color.RgbToLab(*args, **kwargs)[source]#

Convert an image from RGB to Lab.

The image data is assumed to be in the range of \([0, 1]\). Lab color is computed using the D65 illuminant and Observer 2.

Returns:

Lab version of the image.

Shape:
  • image: \((*, 3, H, W)\)

  • output: \((*, 3, H, W)\)

Examples

>>> input = torch.rand(2, 3, 4, 5)
>>> lab = RgbToLab()
>>> output = lab(input)  # 2x3x4x5
Reference:

[1] https://docs.opencv.org/4.0.1/de/d25/imgproc_color_conversions.html

[2] https://www.easyrgb.com/en/math.php

[3] torch/image

class kornia.color.LabToRgb(*args, **kwargs)[source]#

Convert an image from Lab to RGB.

Returns:

RGB version of the image. Range may not be in \([0, 1]\).

Shape:
  • image: \((*, 3, H, W)\)

  • output: \((*, 3, H, W)\)

Examples

>>> input = torch.rand(2, 3, 4, 5)
>>> rgb = LabToRgb()
>>> output = rgb(input)  # 2x3x4x5

References

[1] https://docs.opencv.org/4.0.1/de/d25/imgproc_color_conversions.html

[2] https://www.easyrgb.com/en/math.php

[3] torch/image