Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

add missing docstrings to color module (#3712)

Jeevang1-epic9ffbca8b19aa
diff --git a/kornia/color/gray.py b/kornia/color/gray.py
index 991614f5b..7850435a6 100644
--- a/kornia/color/gray.py
+++ b/kornia/color/gray.py
@@ -157,6 +157,16 @@ class GrayscaleToRgb(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert a grayscale tensor to RGB.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 1, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``1`` is a single grayscale channel, and ``H``/``W`` are height and width.
+
+ Returns:
+ RGB tensor with shape :math:`(*, 3, H, W)`.
+ """
return grayscale_to_rgb(image)
@@ -189,6 +199,16 @@ class RgbToGrayscale(nn.Module):
self.rgb_weights = rgb_weights
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert an RGB tensor to grayscale.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to RGB channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ Grayscale tensor with shape :math:`(*, 1, H, W)`, computed with the module's RGB weights.
+ """
return rgb_to_grayscale(image, rgb_weights=self.rgb_weights)
@@ -215,4 +235,14 @@ class BgrToGrayscale(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 1, -1, -1]
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert a BGR tensor to grayscale.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to BGR channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ Grayscale tensor with shape :math:`(*, 1, H, W)`.
+ """
return bgr_to_grayscale(image)
diff --git a/kornia/color/hls.py b/kornia/color/hls.py
index ef2783025..f7febc642 100644
--- a/kornia/color/hls.py
+++ b/kornia/color/hls.py
@@ -170,6 +170,16 @@ class RgbToHls(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert an RGB tensor to HLS.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to RGB channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ HLS tensor with shape :math:`(*, 3, H, W)`.
+ """
return rgb_to_hls(image)
@@ -199,4 +209,14 @@ class HlsToRgb(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert an HLS tensor to RGB.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to HLS channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ RGB tensor with shape :math:`(*, 3, H, W)`.
+ """
return hls_to_rgb(image)
diff --git a/kornia/color/hsv.py b/kornia/color/hsv.py
index 94bc7b9a2..8e05e73fd 100644
--- a/kornia/color/hsv.py
+++ b/kornia/color/hsv.py
@@ -145,6 +145,16 @@ class RgbToHsv(nn.Module):
self.eps = eps
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert an RGB tensor to HSV.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` is the channel dimension, and ``H``/``W`` are height and width.
+
+ Returns:
+ HSV tensor with shape :math:`(*, 3, H, W)`.
+ """
return rgb_to_hsv(image, self.eps)
@@ -171,4 +181,14 @@ class HsvToRgb(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert an HSV tensor to RGB.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` is the channel dimension, and ``H``/``W`` are height and width.
+
+ Returns:
+ RGB tensor with shape :math:`(*, 3, H, W)`.
+ """
return hsv_to_rgb(image)
diff --git a/kornia/color/lab.py b/kornia/color/lab.py
index 6a46fe8cc..e42eee8ab 100644
--- a/kornia/color/lab.py
+++ b/kornia/color/lab.py
@@ -177,6 +177,16 @@ class RgbToLab(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert an RGB tensor to Lab.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to RGB channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ Lab tensor with shape :math:`(*, 3, H, W)`.
+ """
return rgb_to_lab(image)
@@ -208,4 +218,15 @@ class LabToRgb(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, image: torch.Tensor, clip: bool = True) -> torch.Tensor:
+ """Convert a Lab tensor to RGB.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to Lab channels, and ``H``/``W`` are height and width.
+ clip: If ``True``, clamp output values to :math:`[0, 1]`.
+
+ Returns:
+ RGB tensor with shape :math:`(*, 3, H, W)`.
+ """
return lab_to_rgb(image, clip)
diff --git a/kornia/color/luv.py b/kornia/color/luv.py
index 073712cdf..6b1f192d0 100644
--- a/kornia/color/luv.py
+++ b/kornia/color/luv.py
@@ -170,6 +170,16 @@ class RgbToLuv(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert an RGB tensor to Luv.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to RGB channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ Luv tensor with shape :math:`(*, 3, H, W)`.
+ """
return rgb_to_luv(image)
@@ -201,4 +211,14 @@ class LuvToRgb(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert a Luv tensor to RGB.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to Luv channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ RGB tensor with shape :math:`(*, 3, H, W)`.
+ """
return luv_to_rgb(image)
diff --git a/kornia/color/raw.py b/kornia/color/raw.py
index 542b06028..2fba35d66 100644
--- a/kornia/color/raw.py
+++ b/kornia/color/raw.py
@@ -317,6 +317,16 @@ class RawToRgb(nn.Module):
self.cfa = cfa
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert a Bayer raw tensor to RGB.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 1, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``1`` is a single raw Bayer channel, and ``H``/``W`` are height and width.
+
+ Returns:
+ RGB tensor with shape :math:`(*, 3, H, W)` using this module's CFA pattern.
+ """
return raw_to_rgb(image, cfa=self.cfa)
@@ -347,6 +357,16 @@ class RgbToRaw(nn.Module):
self.cfa = cfa
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert an RGB tensor to Bayer raw.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to RGB channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ Raw tensor with shape :math:`(*, 1, H, W)` using this module's CFA pattern.
+ """
return rgb_to_raw(image, cfa=self.cfa)
@@ -372,4 +392,14 @@ class RawToRgb2x2Downscaled(nn.Module):
self.cfa = cfa
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert a Bayer raw tensor to downscaled RGB.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 1, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``1`` is a single raw Bayer channel, and ``H``/``W`` are height and width.
+
+ Returns:
+ RGB tensor with shape :math:`(*, 3, H / 2, W / 2)`.
+ """
return raw_to_rgb_2x2_downscaled(image, cfa=self.cfa)
diff --git a/kornia/color/rgb.py b/kornia/color/rgb.py
index a72e2a8c7..d3ec0763c 100644
--- a/kornia/color/rgb.py
+++ b/kornia/color/rgb.py
@@ -380,6 +380,16 @@ class BgrToRgb(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert a BGR tensor to RGB.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to BGR channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ RGB tensor with shape :math:`(*, 3, H, W)`.
+ """
return bgr_to_rgb(image)
@@ -406,6 +416,16 @@ class RgbToBgr(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert an RGB tensor to BGR.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to RGB channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ BGR tensor with shape :math:`(*, 3, H, W)`.
+ """
return rgb_to_bgr(image)
@@ -442,6 +462,16 @@ class RgbToRgba(nn.Module):
self.alpha_val = alpha_val
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert an RGB tensor to RGBA.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to RGB channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ RGBA tensor with shape :math:`(*, 4, H, W)` using this module's alpha value.
+ """
return rgb_to_rgba(image, self.alpha_val)
@@ -478,6 +508,16 @@ class BgrToRgba(nn.Module):
self.alpha_val = alpha_val
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Append this module's alpha channel to the input tensor.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` is the input channel count, and ``H``/``W`` are height and width.
+
+ Returns:
+ RGBA tensor with shape :math:`(*, 4, H, W)`.
+ """
return bgr_to_rgba(image, self.alpha_val)
@@ -504,6 +544,16 @@ class RgbaToRgb(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert an RGBA tensor to RGB.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 4, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``4`` corresponds to RGBA channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ RGB tensor with shape :math:`(*, 3, H, W)`.
+ """
return rgba_to_rgb(image)
@@ -530,6 +580,16 @@ class RgbaToBgr(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert an RGBA tensor to BGR.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 4, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``4`` corresponds to RGBA channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ BGR tensor with shape :math:`(*, 3, H, W)`.
+ """
return rgba_to_bgr(image)
@@ -564,6 +624,16 @@ class RgbToLinearRgb(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert an sRGB tensor to linear RGB.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to RGB channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ Linear RGB tensor with shape :math:`(*, 3, H, W)`.
+ """
return rgb_to_linear_rgb(image)
@@ -597,6 +667,16 @@ class LinearRgbToRgb(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert a linear RGB tensor to sRGB.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to RGB channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ sRGB tensor with shape :math:`(*, 3, H, W)`.
+ """
return linear_rgb_to_rgb(image)
@@ -618,6 +698,16 @@ class NormalsToRgb255(nn.Module):
"""
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert surface normals to RGB values in :math:`[0, 255]`.
+
+ Args:
+ image: Input normal map tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to XYZ normal components, and ``H``/``W`` are height and width.
+
+ Returns:
+ RGB tensor in :math:`[0, 255]` with shape :math:`(*, 3, H, W)`.
+ """
return normals_to_rgb255(image)
@@ -639,6 +729,16 @@ class RgbToRgb255(nn.Module):
"""
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert RGB values from :math:`[0, 1]` to :math:`[0, 255]`.
+
+ Args:
+ image: Input RGB tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to RGB channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ RGB tensor in :math:`[0, 255]` with shape :math:`(*, 3, H, W)`.
+ """
return rgb_to_rgb255(image)
@@ -660,6 +760,16 @@ class Rgb255ToRgb(nn.Module):
"""
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert RGB values from :math:`[0, 255]` to :math:`[0, 1]`.
+
+ Args:
+ image: Input RGB tensor in :math:`[0, 255]` with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to RGB channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ RGB tensor in :math:`[0, 1]` with shape :math:`(*, 3, H, W)`.
+ """
return rgb255_to_rgb(image)
@@ -681,4 +791,14 @@ class Rgb255ToNormals(nn.Module):
"""
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert RGB values in :math:`[0, 255]` to surface normals.
+
+ Args:
+ image: Input RGB tensor in :math:`[0, 255]` with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to RGB channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ Normal map tensor with shape :math:`(*, 3, H, W)`.
+ """
return rgb255_to_normals(image)
diff --git a/kornia/color/xyz.py b/kornia/color/xyz.py
index df0e4fd85..b4eaa0d5a 100644
--- a/kornia/color/xyz.py
+++ b/kornia/color/xyz.py
@@ -165,6 +165,16 @@ class RgbToXyz(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert an RGB tensor to XYZ.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to RGB channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ XYZ tensor with shape :math:`(*, 3, H, W)`.
+ """
return rgb_to_xyz(image)
@@ -192,4 +202,14 @@ class XyzToRgb(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert an XYZ tensor to RGB.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to XYZ channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ RGB tensor with shape :math:`(*, 3, H, W)`.
+ """
return xyz_to_rgb(image)
diff --git a/kornia/color/ycbcr.py b/kornia/color/ycbcr.py
index 4f0d8571c..082bf0e36 100644
--- a/kornia/color/ycbcr.py
+++ b/kornia/color/ycbcr.py
@@ -148,6 +148,16 @@ class RgbToYcbcr(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert an RGB tensor to YCbCr.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to RGB channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ YCbCr tensor with shape :math:`(*, 3, H, W)`.
+ """
return rgb_to_ycbcr(image)
@@ -174,4 +184,14 @@ class YcbcrToRgb(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, image: torch.Tensor) -> torch.Tensor:
+ """Convert a YCbCr tensor to RGB.
+
+ Args:
+ image: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to YCbCr channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ RGB tensor with shape :math:`(*, 3, H, W)`.
+ """
return ycbcr_to_rgb(image)
diff --git a/kornia/color/yuv.py b/kornia/color/yuv.py
index 2f8380c12..c4c11069a 100644
--- a/kornia/color/yuv.py
+++ b/kornia/color/yuv.py
@@ -296,6 +296,16 @@ class RgbToYuv(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, input: torch.Tensor) -> torch.Tensor:
+ """Convert an RGB tensor to YUV.
+
+ Args:
+ input: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to RGB channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ YUV tensor with shape :math:`(*, 3, H, W)`.
+ """
return rgb_to_yuv(input)
@@ -331,6 +341,18 @@ class RgbToYuv420(nn.Module):
ONNX_EXPORTABLE = False
def forward(self, yuvinput: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]: # skipcq: PYL-R0201
+ """Convert an RGB tensor to YUV420 planes.
+
+ Args:
+ yuvinput: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to RGB channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ Tuple of ``(y, uv)`` where ``y`` has shape :math:`(*, 1, H, W)` and ``uv`` has
+ shape :math:`(*, 2, H / 2, W / 2)`. The ``1`` channel is luma and the ``2``
+ channels are chroma.
+ """
return rgb_to_yuv420(yuvinput)
@@ -366,6 +388,18 @@ class RgbToYuv422(nn.Module):
ONNX_EXPORTABLE = False
def forward(self, yuvinput: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]: # skipcq: PYL-R0201
+ """Convert an RGB tensor to YUV422 planes.
+
+ Args:
+ yuvinput: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to RGB channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ Tuple of ``(y, uv)`` where ``y`` has shape :math:`(*, 1, H, W)` and ``uv`` has
+ shape :math:`(*, 2, H, W / 2)`. The ``1`` channel is luma and the ``2`` channels
+ are chroma.
+ """
return rgb_to_yuv422(yuvinput)
@@ -397,6 +431,16 @@ class YuvToRgb(nn.Module):
ONNX_DEFAULT_OUTPUTSHAPE: ClassVar[list[int]] = [-1, 3, -1, -1]
def forward(self, input: torch.Tensor) -> torch.Tensor:
+ """Convert a YUV tensor to RGB.
+
+ Args:
+ input: Input tensor with shape :math:`(*, 3, H, W)`.
+ Here, ``*`` means any number of leading dimensions (for example, batch size),
+ ``3`` corresponds to YUV channels, and ``H``/``W`` are height and width.
+
+ Returns:
+ RGB tensor with shape :math:`(*, 3, H, W)`.
+ """
return yuv_to_rgb(input)
@@ -432,6 +476,17 @@ class Yuv420ToRgb(nn.Module):
ONNX_EXPORTABLE = False
def forward(self, inputy: torch.Tensor, inputuv: torch.Tensor) -> torch.Tensor: # skipcq: PYL-R0201
+ """Convert YUV420 luma/chroma planes to RGB.
+
+ Args:
+ inputy: Luma tensor with shape :math:`(*, 1, H, W)`.
+ inputuv: Chroma tensor with shape :math:`(*, 2, H / 2, W / 2)`.
+ For both tensors, ``*`` means any number of leading dimensions (for example,
+ batch size), and ``H``/``W`` are the full-resolution height and width.
+
+ Returns:
+ RGB tensor with shape :math:`(*, 3, H, W)`.
+ """
return yuv420_to_rgb(inputy, inputuv)
@@ -467,4 +522,15 @@ class Yuv422ToRgb(nn.Module):
ONNX_EXPORTABLE = False
def forward(self, inputy: torch.Tensor, inputuv: torch.Tensor) -> torch.Tensor: # skipcq: PYL-R0201
+ """Convert YUV422 luma/chroma planes to RGB.
+
+ Args:
+ inputy: Luma tensor with shape :math:`(*, 1, H, W)`.
+ inputuv: Chroma tensor with shape :math:`(*, 2, H, W / 2)`.
+ For both tensors, ``*`` means any number of leading dimensions (for example,
+ batch size), and ``H``/``W`` are the full-resolution height and width.
+
+ Returns:
+ RGB tensor with shape :math:`(*, 3, H, W)`.
+ """
return yuv422_to_rgb(inputy, inputuv)