Linear RGB#
Tip
Learn more: https://en.wikipedia.org/wiki/SRGB
Functions#
- kornia.color.rgb_to_linear_rgb(image)[source]#
Convert an sRGB image to linear RGB. Used in colorspace conversions.
- Convention:
Converts nonlinear unit-range sRGB to linear RGB channelwise. It is the companion of linear_rgb_to_rgb and the required preparation for rgb_to_xyz.
- Parameters:
image (
Tensor) – sRGB Image to be converted to linear RGB of shape \((*,3,H,W)\).- Return type:
- 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.
- Convention:
Converts linear RGB to nonlinear unit-range sRGB channelwise.
- Parameters:
image (
Tensor) – linear RGB Image to be converted to sRGB of shape \((*,3,H,W)\).- Return type:
- 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.
See the Convention block on
rgb_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
- class kornia.color.LinearRgbToRgb(*args, **kwargs)[source]#
Convert a linear RGB image to sRGB.
See the Convention block on
linear_rgb_to_rgb().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