CIE Luv#

Functions#

kornia.color.rgb_to_luv(image, eps=1e-12)[source]#

Convert an sRGB image to Luv.

luv = rgb_to_luv(image) converts a (*, 3, H, W) sRGB image in \([0, 1]\) to CIE Luv with the D65 white point and the 2° observer. L is in \([0, 100]\).

_images/rgb_to_luv.png
Convention:

Float16 and bfloat16 inputs are computed in float32 and rounded to the input dtype at return. Channels are L, u, v at axis -3. The sRGB curve is removed inside, so pass sRGB, not linear RGB. The scale is that of OpenCV’s float32 Luv, not of its 8-bit Luv, and the values match skimage rgb2luv.

Parameters:
  • image (Tensor) – sRGB image with shape (*, 3, H, W).

  • eps (float, optional) – added to the divisor x + 15 y + 3 z. eps=0 gives NaN in U and V on black pixels. Default: 1e-12

Return type:

Tensor

Returns:

Luv image with shape (*, 3, H, W).

See also

Example

>>> input = torch.rand(2, 3, 4, 5)
>>> output = rgb_to_luv(input)  # 2x3x4x5
kornia.color.luv_to_rgb(image, eps=1e-12)[source]#

Convert a Luv image to sRGB.

rgb = luv_to_rgb(image) converts a (*, 3, H, W) CIE Luv image with the D65 white point and the 2° observer to sRGB. L is expected in \([0, 100]\).

Convention:

Float16 and bfloat16 inputs are computed in float32 and rounded to the input dtype at return. Channels are L, u, v at axis -3. The result is not clipped, so out-of-gamut Luv values give RGB values outside \([0, 1]\).

Parameters:
  • image (Tensor) – Luv image with shape (*, 3, H, W).

  • eps (float, optional) – added to the divisors of the inverse formula. eps=0 gives NaN on black pixels. Default: 1e-12

Return type:

Tensor

Returns:

sRGB image with shape (*, 3, H, W).

See also

Example

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

Modules#

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

Convert an image from sRGB to Luv (module form).

out = RgbToLuv()(image) is rgb_to_luv() with its default eps.

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

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

See also

Examples

>>> input = torch.rand(2, 3, 4, 5)
>>> luv = RgbToLuv()
>>> output = luv(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] http://www.poynton.com/ColorFAQ.html

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

Convert an image from Luv to sRGB (module form).

out = LuvToRgb()(image) is luv_to_rgb() with its default eps.

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

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

See also

Examples

>>> input = torch.rand(2, 3, 4, 5)
>>> rgb = LuvToRgb()
>>> 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] http://www.poynton.com/ColorFAQ.html