Linear RGB#
Convert sRGB to linear RGB with rgb_to_linear_rgb() before rgb_to_xyz(), and back with
linear_rgb_to_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.
lin = rgb_to_linear_rgb(image)removes the sRGB transfer curve from a unit-range(*, 3, H, W)image. Convert beforergb_to_xyz(), which expects linear RGB.
- Convention:
Applies the curve channelwise:
x / 12.92up to 0.04045 and((x + 0.055) / 1.055) ** 2.4above it. Values outside \([0, 1]\) follow the same formulas without clipping.
- Parameters:
image (
Tensor) – sRGB image with shape(*, 3, H, W).- Return type:
- Returns:
Linear RGB image with shape
(*, 3, H, W).
See also
linear_rgb_to_rgb(): the inverse.RgbToLinearRgb: the module form.
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 ofxyz_to_rgb().- Convention:
Applies the curve channelwise:
12.92 * xup to 0.0031308 and1.055 * x ** (1 / 2.4) - 0.055above it. Values outside \([0, 1]\) follow the same formulas without clipping.
- Parameters:
image (
Tensor) – linear RGB image with shape(*, 3, H, W).- Return type:
- Returns:
sRGB image with shape
(*, 3, H, W).
See also
rgb_to_linear_rgb(): removes the curve.LinearRgbToRgb: the module form.
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)isrgb_to_linear_rgb().- Convention:
See the convention block of
rgb_to_linear_rgb().
- Shape:
image:
(*, 3, H, W)output:
(*, 3, H, W)
See also
rgb_to_linear_rgb(): the one-call form.LinearRgbToRgb: the inverse.
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 an image from linear RGB to sRGB (module form).
out = LinearRgbToRgb()(image)islinear_rgb_to_rgb().- Convention:
See the convention block of
linear_rgb_to_rgb().
- Shape:
image:
(*, 3, H, W)output:
(*, 3, H, W)
See also
linear_rgb_to_rgb(): the one-call form.RgbToLinearRgb: removes the curve.
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