CIE Lab#
Tip
Learn more: https://en.wikipedia.org/wiki/CIELAB_color_space
Functions#
- kornia.color.rgb_to_lab(image)[source]#
Convert an sRGB image to Lab.
lab = rgb_to_lab(image)converts a(*, 3, H, W)sRGB image in \([0, 1]\) to CIE Lab with the D65 white point and the 2° observer. L is in \([0, 100]\), and a and b lie within \([-128, 127]\).
- Convention:
Float16 and bfloat16 inputs are computed in float32 and rounded to the input dtype at return. Channels are
L,a,bat axis -3. The sRGB curve is removed inside, so pass sRGB, not linear RGB. The scale is that of OpenCV’s float32 Lab, not of its 8-bit Lab, where L is scaled to 0..255 and a and b are offset by 128. Values match skimagergb2lab. OpenCV 5’s floatCOLOR_RGB2Labquantizes its input, so it differs by less than 1 in each channel.
- Parameters:
image (
Tensor) – sRGB image with shape(*, 3, H, W).- Return type:
- Returns:
Lab image with shape
(*, 3, H, W).
See also
lab_to_rgb(): the inverse.RgbToLab: the module form.
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 sRGB.
rgb = lab_to_rgb(image)converts a(*, 3, H, W)CIE Lab image with the D65 white point and the 2° observer to sRGB. L is expected in \([0, 100]\), and a and b in \([-128, 127]\).- Convention:
Float16 and bfloat16 inputs are computed in float32 and rounded to the input dtype at return. Channels are
L,a,bat axis -3.
- Parameters:
- Return type:
- Returns:
sRGB image with shape
(*, 3, H, W).
See also
rgb_to_lab(): the inverse.LabToRgb: the module form, which takesclipwhen called.
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 sRGB to Lab (module form).
out = RgbToLab()(image)isrgb_to_lab().- Convention:
See the convention block of
rgb_to_lab().
- Shape:
image:
(*, 3, H, W)output:
(*, 3, H, W)
See also
rgb_to_lab(): the one-call form.LabToRgb: the inverse.
Examples
>>> input = torch.rand(2, 3, 4, 5) >>> lab = RgbToLab() >>> output = lab(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
- class kornia.color.LabToRgb(*args, **kwargs)[source]#
Convert an image from Lab to sRGB (module form).
out = LabToRgb()(image, clip)islab_to_rgb().clipis an argument of the call, not of the constructor.- Convention:
See the convention block of
lab_to_rgb().
- Shape:
image:
(*, 3, H, W)output:
(*, 3, H, W)
See also
lab_to_rgb(): the one-call form.RgbToLab: the inverse.
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