YCbCr#
Tip
Learn more: https://en.wikipedia.org/wiki/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.
- Convention:
Channels are Y, Cb, Cr at axis -3. The values equal OpenCV’s float
COLOR_RGB2YCrCb, which stores Cr before Cb. skimagergb2ycbcrdiffers: it uses studio range, with Y in 16..235.
- Parameters:
image (
Tensor) – RGB image with shape(*, 3, H, W).- Return type:
- Returns:
YCbCr image with shape
(*, 3, H, W).
See also
ycbcr_to_rgb(): the inverse.rgb_to_y(): keeps only the Y channel.RgbToYcbcr: the module form.
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:
- Returns:
Y image with shape
(*, 1, H, W).
See also
rgb_to_ycbcr(): returns Cb and Cr as well.rgb_to_grayscale(): the same weights by default, with customrgb_weightsallowed.
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 asrgb_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:
- Returns:
RGB image with shape
(*, 3, H, W).
See also
rgb_to_ycbcr(): the inverse.YcbcrToRgb: the module form.
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)isrgb_to_ycbcr().- Convention:
See the convention block of
rgb_to_ycbcr().
- Shape:
image:
(*, 3, H, W)output:
(*, 3, H, W)
See also
rgb_to_ycbcr(): the one-call form.YcbcrToRgb: the inverse.
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)isycbcr_to_rgb().- Convention:
See the convention block of
ycbcr_to_rgb().
- Shape:
image:
(*, 3, H, W)output:
(*, 3, H, W)
See also
ycbcr_to_rgb(): the one-call form.RgbToYcbcr: the inverse.
Examples
>>> input = torch.rand(2, 3, 4, 5) >>> rgb = YcbcrToRgb() >>> output = rgb(input) # 2x3x4x5