YCbCr#

Functions#

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

Convert an RGB image to full-range YCbCr.

ycbcr = rgb_to_ycbcr(image) converts a (*, 3, H, W) RGB image in \([0, 1]\) to Y, Cb and Cr with the BT.601 luma weights, all channels in \([0, 1]\) and Cb and Cr centred at 0.5.

_images/rgb_to_ycbcr.png
Convention:

Channels are Y, Cb, Cr at axis -3. The values equal OpenCV’s float COLOR_RGB2YCrCb, which stores Cr before Cb. skimage rgb2ycbcr differs: it uses studio range, with Y in 16..235.

Parameters:

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

Return type:

Tensor

Returns:

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

See also

Examples

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

Convert an RGB image to the Y channel of YCbCr.

y = rgb_to_y(image) returns the BT.601 luma, 0.299 R + 0.587 G + 0.114 B, of a (*, 3, H, W) RGB image in \([0, 1]\) as one channel.

Parameters:

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

Return type:

Tensor

Returns:

Y image with shape (*, 1, H, W).

See also

Examples

>>> input = torch.rand(2, 3, 4, 5)
>>> output = rgb_to_y(input)  # 2x1x4x5
kornia.color.ycbcr_to_rgb(image)[source]#

Convert a full-range YCbCr image to RGB.

rgb = ycbcr_to_rgb(image) converts a (*, 3, H, W) YCbCr image in \([0, 1]\), with Cb and Cr centred at 0.5 as rgb_to_ycbcr() returns them, to RGB.

Convention:

Channels are Y, Cb, Cr at axis -3. The result is clamped to \([0, 1]\).

Parameters:

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

Return type:

Tensor

Returns:

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

See also

Examples

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

Modules#

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

Convert an image from RGB to YCbCr (module form).

out = RgbToYcbcr()(image) is rgb_to_ycbcr().

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

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

See also

Examples

>>> input = torch.rand(2, 3, 4, 5)
>>> ycbcr = RgbToYcbcr()
>>> output = ycbcr(input)  # 2x3x4x5
class kornia.color.YcbcrToRgb(*args, **kwargs)[source]#

Convert an image from YCbCr to RGB (module form).

out = YcbcrToRgb()(image) is ycbcr_to_rgb().

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

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

See also

Examples

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