CIE XYZ#

Note

rgb_to_xyz() takes linear RGB: convert an sRGB image with rgb_to_linear_rgb() first, and the result of xyz_to_rgb() back with linear_rgb_to_rgb(). rgb_to_lab() and rgb_to_luv() take sRGB.

Functions#

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

Convert a linear RGB image to XYZ.

xyz = rgb_to_xyz(image) converts a (*, 3, H, W) linear RGB image to CIE XYZ with the sRGB primaries and the D65 white point. It does not remove the sRGB curve: for an sRGB image, pass the result of rgb_to_linear_rgb().

_images/rgb_to_xyz.png
Convention:

A matrix transform of the channels at axis -3. OpenCV’s COLOR_RGB2XYZ does the same, and skimage rgb2xyz linearizes its input first.

Parameters:

image (Tensor) – linear RGB image with shape (*, 3, H, W).

Return type:

Tensor

Returns:

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

See also

Example

>>> input = torch.rand(2, 3, 4, 5)
>>> output = rgb_to_xyz(input)  # 2x3x4x5
kornia.color.xyz_to_rgb(image)[source]#

Convert an XYZ image to linear RGB.

rgb = xyz_to_rgb(image) converts a (*, 3, H, W) CIE XYZ image with the D65 white point to linear RGB with the sRGB primaries. For an sRGB result, apply linear_rgb_to_rgb() to it.

Convention:

A matrix transform of the channels at axis -3. The result is not clipped.

Parameters:

image (Tensor) – XYZ image with shape (*, 3, H, W).

Return type:

Tensor

Returns:

Linear RGB image with shape (*, 3, H, W).

See also

Example

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

Modules#

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

Convert an image from linear RGB to XYZ (module form).

out = RgbToXyz()(image) is rgb_to_xyz().

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

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

See also

Examples

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

References

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

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

Convert an image from XYZ to linear RGB (module form).

out = XyzToRgb()(image) is xyz_to_rgb().

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

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

See also

Examples

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

References

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