CIE Lab#
Tip
Learn more: https://en.wikipedia.org/wiki/CIELAB_color_space
Functions#
- kornia.color.rgb_to_lab(image)[source]#
Convert a RGB image to Lab.
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.
- Convention:
Float16 and bfloat16 inputs are computed in float32 and rounded to the input dtype at return. Input is nonlinear sRGB in RGB channel order at axis -3; this function first converts it to linear RGB. Output channels are L*, a*, b* using D65 / 2° reference white.
- Parameters:
image (
Tensor) – RGB Image to be converted to Lab with shape \((*, 3, H, W)\).- Return type:
- 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]\).
- Convention:
Float16 and bfloat16 inputs are computed in float32 and rounded to the input dtype at return. Input channels are L*, a*, b* at axis -3 using D65 / 2° reference white. Set clip to false to skip the final [0, 1] clamp of the sRGB output.
- Parameters:
- Return type:
- Returns:
RGB version of the image with shape \((*, 3, H, W)\), in \([0, 1]\) when
clipis True.
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.
See the Convention block on
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
- class kornia.color.LabToRgb(*args, **kwargs)[source]#
Convert an image from Lab to RGB.
See the Convention block on
lab_to_rgb().- Returns:
RGB version of the image, clipped to \([0, 1]\) unless
clipis False.
- 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