From 57ca8f15f06a37654bccdfaf3a55e5211bba8bd3 Mon Sep 17 00:00:00 2001 From: Lucas Egidio <12188889+egidioln@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:42:33 +0200 Subject: [PATCH 1/2] docs: precise yuv flavor in docstrings --- kornia/color/yuv.py | 64 ++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/kornia/color/yuv.py b/kornia/color/yuv.py index 1334be10894..2e1cc5b3798 100644 --- a/kornia/color/yuv.py +++ b/kornia/color/yuv.py @@ -11,7 +11,8 @@ def rgb_to_yuv(image: Tensor) -> Tensor: .. image:: _static/img/rgb_to_yuv.png - The image data is assumed to be in the range of (0, 1). + The image data is assumed to be in the range of :math:`(0, 1)`. The range of the output is of :math:`(0, 1)` to luma and the ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(−0.615, 0.615)`, respectively. + The YUV model adopted here follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). Args: image: RGB Image to be converted to YUV with shape :math:`(*, 3, H, W)`. @@ -45,8 +46,11 @@ def rgb_to_yuv(image: Tensor) -> Tensor: def rgb_to_yuv420(image: Tensor) -> Tuple[Tensor, Tensor]: r"""Convert an RGB image to YUV 420 (subsampled). - The image data is assumed to be in the range of (0, 1). Input need to be padded to be evenly divisible by 2 - horizontal and vertical. This function will output chroma siting (0.5,0.5) + Input need to be padded to be evenly divisible by 2 horizontal and vertical. + + The image data is assumed to be in the range of :math:`(0, 1)`. The range of the output is of :math:`(0, 1)` to luma and the ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(−0.615, 0.615)`, respectively. + The YUV model adopted here follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). + Args: image: RGB Image to be converted to YUV with shape :math:`(*, 3, H, W)`. @@ -76,8 +80,10 @@ def rgb_to_yuv420(image: Tensor) -> Tuple[Tensor, Tensor]: def rgb_to_yuv422(image: Tensor) -> Tuple[Tensor, Tensor]: r"""Convert an RGB image to YUV 422 (subsampled). - The image data is assumed to be in the range of (0, 1). Input need to be padded to be evenly divisible by 2 - vertical. This function will output chroma siting (0.5) + Input need to be padded to be evenly divisible by 2 vertical. + + The image data is assumed to be in the range of :math:`(0, 1)`. The range of the output is of :math:`(0, 1)` to luma and the ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(−0.615, 0.615)`, respectively. + The YUV model adopted here follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). Args: image: RGB Image to be converted to YUV with shape :math:`(*, 3, H, W)`. @@ -107,7 +113,8 @@ def rgb_to_yuv422(image: Tensor) -> Tuple[Tensor, Tensor]: def yuv_to_rgb(image: Tensor) -> Tensor: r"""Convert an YUV image to RGB. - The image data is assumed to be in the range of (0, 1) for luma and (-0.5, 0.5) for chroma. + The image data is assumed to be in the range of :math:`(0, 1)` for luma (Y). The ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(−0.615, 0.615)`, respectively. + YUV formula follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). Args: image: YUV Image to be converted to RGB with shape :math:`(*, 3, H, W)`. @@ -141,9 +148,10 @@ def yuv_to_rgb(image: Tensor) -> Tensor: def yuv420_to_rgb(imagey: Tensor, imageuv: Tensor) -> Tensor: r"""Convert an YUV420 image to RGB. - The image data is assumed to be in the range of (0, 1) for luma and (-0.5, 0.5) for chroma. Input need to be padded to be evenly divisible by 2 horizontal and vertical. - This function assumed chroma siting is (0.5, 0.5) + + The image data is assumed to be in the range of :math:`(0, 1)` for luma (Y). The ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(−0.615, 0.615)`, respectively. + YUV formula follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). Args: imagey: Y (luma) Image plane to be converted to RGB with shape :math:`(*, 1, H, W)`. @@ -192,8 +200,10 @@ def yuv420_to_rgb(imagey: Tensor, imageuv: Tensor) -> Tensor: def yuv422_to_rgb(imagey: Tensor, imageuv: Tensor) -> Tensor: r"""Convert an YUV422 image to RGB. - The image data is assumed to be in the range of (0, 1) for luma and (-0.5, 0.5) for chroma. - Input need to be padded to be evenly divisible by 2 vertical. This function assumed chroma siting is (0.5) + Input need to be padded to be evenly divisible by 2 vertical. + + The image data is assumed to be in the range of :math:`(0, 1)` for luma (Y). The ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(−0.615, 0.615)`, respectively. + YUV formula follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). Args: imagey: Y (luma) Image plane to be converted to RGB with shape :math:`(*, 1, H, W)`. @@ -236,7 +246,9 @@ def yuv422_to_rgb(imagey: Tensor, imageuv: Tensor) -> Tensor: class RgbToYuv(Module): r"""Convert an image from RGB to YUV. - The image data is assumed to be in the range of (0, 1). + The image data is assumed to be in the range of :math:`(0, 1)`. + + YUV formula follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). Returns: YUV version of the image. @@ -261,7 +273,11 @@ def forward(self, input: Tensor) -> Tensor: class RgbToYuv420(Module): r"""Convert an image from RGB to YUV420. - The image data is assumed to be in the range of (0, 1). Width and Height evenly divisible by 2. + Width and Height evenly divisible by 2. + + The image data is assumed to be in the range of :math:`(0, 1)`. + + YUV formula follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). Returns: YUV420 version of the image. @@ -286,7 +302,11 @@ def forward(self, yuvinput: Tensor) -> Tuple[Tensor, Tensor]: # skipcq: PYL-R02 class RgbToYuv422(Module): r"""Convert an image from RGB to YUV422. - The image data is assumed to be in the range of (0, 1). Width evenly disvisible by 2. + Width must be evenly disvisible by 2. + + The image data is assumed to be in the range of :math:`(0, 1)`. + + YUV formula follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). Returns: YUV422 version of the image. @@ -311,7 +331,9 @@ def forward(self, yuvinput: Tensor) -> Tuple[Tensor, Tensor]: # skipcq: PYL-R02 class YuvToRgb(Module): r"""Convert an image from YUV to RGB. - The image data is assumed to be in the range of (0, 1) for luma and (-0.5, 0.5) for chroma. + The image data is assumed to be in the range of :math:`(0, 1)` for luma (Y). The ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(−0.615, 0.615)`, respectively. + + YUV formula follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). Returns: RGB version of the image. @@ -333,8 +355,11 @@ def forward(self, input: Tensor) -> Tensor: class Yuv420ToRgb(Module): r"""Convert an image from YUV to RGB. - The image data is assumed to be in the range of (0, 1) for luma and (-0.5, 0.5) for chroma. - Width and Height evenly divisible by 2. + Width and Height must be evenly divisible by 2. + + The image data is assumed to be in the range of :math:`(0, 1)` for luma (Y). The ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(−0.615, 0.615)`, respectively. + + YUV formula follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). Returns: RGB version of the image. @@ -358,8 +383,11 @@ def forward(self, inputy: Tensor, inputuv: Tensor) -> Tensor: # skipcq: PYL-R02 class Yuv422ToRgb(Module): r"""Convert an image from YUV to RGB. - The image data is assumed to be in the range of (0, 1) for luma and (-0.5, 0.5) for chroma. - Width evenly divisible by 2. + Width must be evenly divisible by 2. + + The image data is assumed to be in the range of :math:`(0, 1)` for luma (Y). The ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(−0.615, 0.615)`, respectively. + + YUV formula follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). Returns: RGB version of the image. From a3fab359a70ba1e0ffdab15b0cd0746ed31e42dd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 9 Sep 2024 18:48:03 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- kornia/color/yuv.py | 92 ++++++++++++++++++++++++++++++++------------- 1 file changed, 66 insertions(+), 26 deletions(-) diff --git a/kornia/color/yuv.py b/kornia/color/yuv.py index 2e1cc5b3798..bf620c83ed3 100644 --- a/kornia/color/yuv.py +++ b/kornia/color/yuv.py @@ -11,8 +11,13 @@ def rgb_to_yuv(image: Tensor) -> Tensor: .. image:: _static/img/rgb_to_yuv.png - The image data is assumed to be in the range of :math:`(0, 1)`. The range of the output is of :math:`(0, 1)` to luma and the ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(−0.615, 0.615)`, respectively. - The YUV model adopted here follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). + The image data is assumed to be in the range of :math:`(0, 1)`. The range of the output is of + :math:`(0, 1)` to luma and the ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(-0.615, 0.615)`, + respectively. + + The YUV model adopted here follows M/PAL values (see + `BT.470-5 `_, Table 2, + items 2.5 and 2.6). Args: image: RGB Image to be converted to YUV with shape :math:`(*, 3, H, W)`. @@ -48,9 +53,12 @@ def rgb_to_yuv420(image: Tensor) -> Tuple[Tensor, Tensor]: Input need to be padded to be evenly divisible by 2 horizontal and vertical. - The image data is assumed to be in the range of :math:`(0, 1)`. The range of the output is of :math:`(0, 1)` to luma and the ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(−0.615, 0.615)`, respectively. - The YUV model adopted here follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). + The image data is assumed to be in the range of :math:`(0, 1)`. The range of the output is of :math:`(0, 1)` to + luma and the ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(-0.615, 0.615)`, respectively. + The YUV model adopted here follows M/PAL values (see + `BT.470-5 `_, Table 2, + items 2.5 and 2.6). Args: image: RGB Image to be converted to YUV with shape :math:`(*, 3, H, W)`. @@ -82,8 +90,13 @@ def rgb_to_yuv422(image: Tensor) -> Tuple[Tensor, Tensor]: Input need to be padded to be evenly divisible by 2 vertical. - The image data is assumed to be in the range of :math:`(0, 1)`. The range of the output is of :math:`(0, 1)` to luma and the ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(−0.615, 0.615)`, respectively. - The YUV model adopted here follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). + The image data is assumed to be in the range of :math:`(0, 1)`. The range of the output is of + :math:`(0, 1)` to luma and the ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(-0.615, 0.615)`, + respectively. + + The YUV model adopted here follows M/PAL values (see + `BT.470-5 `_, Table 2, + items 2.5 and 2.6). Args: image: RGB Image to be converted to YUV with shape :math:`(*, 3, H, W)`. @@ -113,8 +126,12 @@ def rgb_to_yuv422(image: Tensor) -> Tuple[Tensor, Tensor]: def yuv_to_rgb(image: Tensor) -> Tensor: r"""Convert an YUV image to RGB. - The image data is assumed to be in the range of :math:`(0, 1)` for luma (Y). The ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(−0.615, 0.615)`, respectively. - YUV formula follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). + The image data is assumed to be in the range of :math:`(0, 1)` for luma (Y). The ranges of U and V are + :math:`(-0.436, 0.436)` and :math:`(-0.615, 0.615)`, respectively. + + YUV formula follows M/PAL values (see + `BT.470-5 `_, Table 2, + items 2.5 and 2.6). Args: image: YUV Image to be converted to RGB with shape :math:`(*, 3, H, W)`. @@ -150,8 +167,12 @@ def yuv420_to_rgb(imagey: Tensor, imageuv: Tensor) -> Tensor: Input need to be padded to be evenly divisible by 2 horizontal and vertical. - The image data is assumed to be in the range of :math:`(0, 1)` for luma (Y). The ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(−0.615, 0.615)`, respectively. - YUV formula follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). + The image data is assumed to be in the range of :math:`(0, 1)` for luma (Y). The ranges of U and V are + :math:`(-0.436, 0.436)` and :math:`(-0.615, 0.615)`, respectively. + + YUV formula follows M/PAL values (see + `BT.470-5 `_, Table 2, + items 2.5 and 2.6). Args: imagey: Y (luma) Image plane to be converted to RGB with shape :math:`(*, 1, H, W)`. @@ -200,10 +221,14 @@ def yuv420_to_rgb(imagey: Tensor, imageuv: Tensor) -> Tensor: def yuv422_to_rgb(imagey: Tensor, imageuv: Tensor) -> Tensor: r"""Convert an YUV422 image to RGB. - Input need to be padded to be evenly divisible by 2 vertical. + Input need to be padded to be evenly divisible by 2 vertical. + + The image data is assumed to be in the range of :math:`(0, 1)` for luma (Y). The ranges of U and V are + :math:`(-0.436, 0.436)` and :math:`(-0.615, 0.615)`, respectively. - The image data is assumed to be in the range of :math:`(0, 1)` for luma (Y). The ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(−0.615, 0.615)`, respectively. - YUV formula follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). + YUV formula follows M/PAL values (see + `BT.470-5 `_, Table 2, + items 2.5 and 2.6). Args: imagey: Y (luma) Image plane to be converted to RGB with shape :math:`(*, 1, H, W)`. @@ -248,7 +273,9 @@ class RgbToYuv(Module): The image data is assumed to be in the range of :math:`(0, 1)`. - YUV formula follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). + YUV formula follows M/PAL values (see + `BT.470-5 `_, Table 2, + items 2.5 and 2.6). Returns: YUV version of the image. @@ -277,7 +304,9 @@ class RgbToYuv420(Module): The image data is assumed to be in the range of :math:`(0, 1)`. - YUV formula follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). + YUV formula follows M/PAL values (see + `BT.470-5 `_, Table 2, + items 2.5 and 2.6). Returns: YUV420 version of the image. @@ -304,9 +333,11 @@ class RgbToYuv422(Module): Width must be evenly disvisible by 2. - The image data is assumed to be in the range of :math:`(0, 1)`. + The image data is assumed to be in the range of :math:`(0, 1)`. - YUV formula follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). + YUV formula follows M/PAL values (see + `BT.470-5 `_, Table 2, + items 2.5 and 2.6). Returns: YUV422 version of the image. @@ -331,9 +362,12 @@ def forward(self, yuvinput: Tensor) -> Tuple[Tensor, Tensor]: # skipcq: PYL-R02 class YuvToRgb(Module): r"""Convert an image from YUV to RGB. - The image data is assumed to be in the range of :math:`(0, 1)` for luma (Y). The ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(−0.615, 0.615)`, respectively. - - YUV formula follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). + The image data is assumed to be in the range of :math:`(0, 1)` for luma (Y). The ranges of U and V are + :math:`(-0.436, 0.436)` and :math:`(-0.615, 0.615)`, respectively. + + YUV formula follows M/PAL values (see + `BT.470-5 `_, Table 2, + items 2.5 and 2.6). Returns: RGB version of the image. @@ -357,9 +391,12 @@ class Yuv420ToRgb(Module): Width and Height must be evenly divisible by 2. - The image data is assumed to be in the range of :math:`(0, 1)` for luma (Y). The ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(−0.615, 0.615)`, respectively. + The image data is assumed to be in the range of :math:`(0, 1)` for luma (Y). The ranges of U and V are + :math:`(-0.436, 0.436)` and :math:`(-0.615, 0.615)`, respectively. - YUV formula follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). + YUV formula follows M/PAL values (see + `BT.470-5 `_, Table 2, + items 2.5 and 2.6). Returns: RGB version of the image. @@ -384,10 +421,13 @@ class Yuv422ToRgb(Module): r"""Convert an image from YUV to RGB. Width must be evenly divisible by 2. - - The image data is assumed to be in the range of :math:`(0, 1)` for luma (Y). The ranges of U and V are :math:`(-0.436, 0.436)` and :math:`(−0.615, 0.615)`, respectively. - - YUV formula follows M/PAL values (see [BT.470-5](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.470-5-199802-S!!PDF-E.pdf), Table 2, items 2.5 and 2.6). + + The image data is assumed to be in the range of :math:`(0, 1)` for luma (Y). The ranges of U and V are + :math:`(-0.436, 0.436)` and :math:`(-0.615, 0.615)`, respectively. + + YUV formula follows M/PAL values (see + `BT.470-5 `_, Table 2, + items 2.5 and 2.6). Returns: RGB version of the image.