Linear RGB#

Functions#

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

Convert an sRGB image to linear RGB. Used in colorspace conversions.

_images/rgb_to_linear_rgb.png
Parameters:

image (Tensor) – sRGB Image to be converted to linear RGB of shape \((*,3,H,W)\).

Return type:

Tensor

Returns:

linear RGB version of the image with shape of \((*,3,H,W)\).

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. Used in colorspace conversions.

Parameters:

image (Tensor) – linear RGB Image to be converted to sRGB of shape \((*,3,H,W)\).

Return type:

Tensor

Returns:

sRGB version of the image with shape of shape \((*,3,H,W)\).

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.

Reverses the gamma correction of sRGB to get linear RGB values for colorspace conversions. The image data is assumed to be in the range of \([0, 1]\)

Returns:

Linear RGB version of the image.

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

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

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 a linear RGB image to sRGB.

Applies gamma correction to linear RGB values, at the end of colorspace conversions, to get sRGB.

Returns:

sRGB version of the image.

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

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

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