Linear RGB#

Convert sRGB to linear RGB with rgb_to_linear_rgb() before rgb_to_xyz(), and back with linear_rgb_to_rgb().

Functions#

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

Convert an sRGB image to linear RGB.

lin = rgb_to_linear_rgb(image) removes the sRGB transfer curve from a unit-range (*, 3, H, W) image. Convert before rgb_to_xyz(), which expects linear RGB.

_images/rgb_to_linear_rgb.png
Convention:

Applies the curve channelwise: x / 12.92 up to 0.04045 and ((x + 0.055) / 1.055) ** 2.4 above it. Values outside \([0, 1]\) follow the same formulas without clipping.

Parameters:

image (Tensor) – sRGB 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 = rgb_to_linear_rgb(input) # 2x3x4x5
kornia.color.linear_rgb_to_rgb(image)[source]#

Convert a linear RGB image to sRGB.

rgb = linear_rgb_to_rgb(image) applies the sRGB transfer curve to a unit-range (*, 3, H, W) linear-light image, for example the result of xyz_to_rgb().

Convention:

Applies the curve channelwise: 12.92 * x up to 0.0031308 and 1.055 * x ** (1 / 2.4) - 0.055 above it. Values outside \([0, 1]\) follow the same formulas without clipping.

Parameters:

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

Return type:

Tensor

Returns:

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

See also

Example

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

Modules#

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

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

out = RgbToLinearRgb()(image) is rgb_to_linear_rgb().

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

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

See also

Example

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

References

[1] https://stackoverflow.com/questions/35952564/convert-rgb-to-srgb

[2] https://www.cambridgeincolour.com/tutorials/gamma-correction.htm

[3] https://en.wikipedia.org/wiki/SRGB

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

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

out = LinearRgbToRgb()(image) is linear_rgb_to_rgb().

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

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

See also

Example

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

References

[1] https://stackoverflow.com/questions/35952564/convert-rgb-to-srgb

[2] https://www.cambridgeincolour.com/tutorials/gamma-correction.htm

[3] https://en.wikipedia.org/wiki/SRGB