imgtools.color

Transformations about color models.

Color Space Transformations

Provides color space transformations between color spaces. Except LMS space, all the color spaces can be converted from/to RGB color space.

  • RGB based color spacesRGB, YUV, HSV, HSL, HSI, HWB
    • RGBRed Green Blue<br>

      Most color space can be transformed from this space. Supports the linearize and the gamma-ize of several RGB models: sRGB, Display P3, Adobe RGB, wide-gamut, ProPhoto RGB, REC. 2020.

    • YUVLuminance u v<br>

      The color space used in the television. The coefficients of Y channel follows the SDTV standard (BT.470). And the U, V channels are scaled to the range of [-0.5, 0.5].

    • HSVHue Saturation Value<br>

      A cylindrical-coordinate representation in an RGB color model. The resulting solid is a cone.

    • HSLHue Saturation Lightness<br>

      A cylindrical-coordinate representation in an RGB color model. The resulting solid is a bicone.

    • HSIHue Saturation Intensity<br>

      A cylindrical-coordinate representation in an RGB color model. The resulting solid is a bicone.

    • HWBHue Whitness Blackness<br>

      A cylindrical-coordinate of RGB color model.

    • GrayGrayscale<br>

      Same as the Y channel of YUV color space.

  • CIE based color spaces: CIE XYZ, LMS, CIE LAB, CIE LUV
    • CIE XYZX Y Z<br>

      CIE 1931 color space, which define the relationship between the visible spectrum and human color vision.

    • LMSlong medium short<br>

      The cone response space, which is based on the human visual system. This space can only be converted from/to CIE XYZ space.

    • CIE LABLightness a* b*<br>

      L*a*b* color space, which was intended as a perceptually uniform space. a* represents green-red opponent colors, and b* represents blue-yellow opponent colors.

    • CIE LUVLightness u* v*<br>

      L*u*v* color space, which attempted perceptual uniformity, like L*a*b*.

  • Other color spaces: HED
    • HEDHaematoxylin Eosin DAB

      Haematoxylin-Eosin-DAB. See [Ruifrok] for details.

Reference

[Ruifrok]A. C. Ruifrok and D. A. Johnston, “Quantification of

histochemical staining by color deconvolution.,” Analytical and quantitative cytology and histology / the International Academy of Cytology [and] American Society of Cytology, vol. 23, no. 4, pp. 291-9, Aug. 2001.



Documents

imgtools.color.lab_to_rgb(lab: Tensor, rgb_spec: str = 'srgb', white: str = 'D65', obs: str | int = 10, ret_matrix: bool = False) Tensor | tuple[Tensor, Tensor]

Converts an image from CIE LAB space to RGB space.

Parameters:
labtorch.Tensor

An image in CIE LAB space with shape (*, 3, H, W).

rgb_specRGBSpec, default=’srgb’

The name of RGB specification. The argument is case-insensitive.

whiteStandardIlluminants, default=’D65’

Reference white point for the rgb to xyz conversion. The input is case-insensitive.

obs{2, ‘2’, 10, ‘10’}, default=10

Degree of the standard observer (2° or 10°).

ret_matrixbool, default=False

If false, only the image is returned. If true, also returns the transformation matrix.

Returns:
rgbtorch.Tensor

An RGB image in [0, 1] with the shape (*, 3, H, W).

mattorch.Tensor

A transformation matrix used to convert CIE XYZ to RGB. mat is returned only if ret_matrix is true.

imgtools.color.lab_to_xyz(lab: Tensor, rgb_spec: str = 'srgb', white: str = 'D65', obs: str | int = 10, ret_matrix: bool = False) Tensor | tuple[Tensor, Tensor]

Converts an image from CIE LAB space to CIE XYZ space.

Parameters:
labtorch.Tensor

An image in CIE LAB space with shape (*, 3, H, W).

rgb_specRGBSpec, default=’srgb’

The name of RGB specification. The argument is case-insensitive.

whiteStandardIlluminants, default=’D65’

Reference white point for the rgb to xyz conversion. The input is case-insensitive.

obs{2, ‘2’, 10, ‘10’}, default=10

Degree of the standard observer (2° or 10°).

ret_matrixbool, default=False

If false, only the image is returned. If true, also returns the transformation matrix.

Returns:
xyztorch.Tensor

An image in CIE XYZ space with the shape (*, 3, H, W).

mattorch.Tensor

A transformation matrix used to convert RGB to CIE XYZ. mat is returned only if ret_matrix is true.

imgtools.color.rgb_to_lab(rgb: Tensor, rgb_spec: str = 'srgb', white: str = 'D65', obs: str | int = 10, ret_matrix: bool = False) Tensor | tuple[Tensor, Tensor]

Converts an image from RGB space to CIE LAB space.

The input is assumed to be in the range of [0, 1]. If rgb_spec is a tensor, then the input rgb is assumed to be linear RGB.

Parameters:
rgbtorch.Tensor

An RGB image in the range of [0, 1] with shape (*, 3, H, W).

rgb_specRGBSpec, default=’srgb’

The name of RGB specification. The argument is case-insensitive.

whiteStandardIlluminants, default=’D65’

Reference white point for the rgb to xyz conversion. The input is case-insensitive.

obs{2, ‘2’, 10, ‘10’}, default=10

Degree of the standard observer (2° or 10°).

ret_matrixbool, default=False

If false, only the image is returned. If true, also returns the transformation matrix.

Returns:
labtorch.Tensor

An image in CIE LAB space with the shape (*, 3, H, W).

mattorch.Tensor

A transformation matrix used to convert RGB to CIE XYZ. mat is returned only if ret_matrix is true.

imgtools.color.xyz_to_lab(xyz: Tensor, rgb_spec: str = 'srgb', white: str = 'D65', obs: str | int = 10, ret_matrix: bool = False) Tensor | tuple[Tensor, Tensor]

Converts an image from CIE XYZ space to CIE LAB space.

Parameters:
xyztorch.Tensor

An image in CIE XYZ space with shape (*, 3, H, W).

rgb_specRGBSpec, default=’srgb’

The name of RGB specification. The argument is case-insensitive.

whiteStandardIlluminants, default=’D65’

Reference white point for the rgb to xyz conversion. The input is case-insensitive.

obs{2, ‘2’, 10, ‘10’}, default=10

Degree of the standard observer (2° or 10°).

ret_matrixbool, default=False

If false, only the image is returned. If true, also returns the transformation matrix.

Returns:
labtorch.Tensor

An image in CIE LAB space with the shape (*, 3, H, W).

mattorch.Tensor

A transformation matrix used to convert RGB to CIE XYZ. mat is returned only if ret_matrix is true.

imgtools.color.luv_to_rgb(luv: Tensor, rgb_spec: str = 'srgb', white: str = 'D65', obs: str | int = 10, ret_matrix: bool = False) Tensor

Converts an image from CIE LUV space to RGB space.

Parameters:
luvtorch.Tensor

An image in CIE LUV space with shape (*, 3, H, W).

rgb_specRGBSpec, default=’srgb’

The name of RGB specification. The argument is case-insensitive.

whiteStandardIlluminants, default=’D65’

Reference white point for the rgb to xyz conversion. The input is case-insensitive.

obs{2, ‘2’, 10, ‘10’}, default=10

Degree of the standard observer (2° or 10°).

ret_matrixbool, default=False

If false, only the image is returned. If true, also returns the transformation matrix.

Returns:
rgbtorch.Tensor

An RGB image in [0, 1] with the shape (*, 3, H, W).

mattorch.Tensor

A transformation matrix used to convert CIE XYZ to RGB. mat is returned only if ret_matrix is true.

imgtools.color.luv_to_xyz(luv: Tensor, rgb_spec: str = 'srgb', white: str = 'D65', obs: str | int = 10, ret_matrix: bool = False)

Converts an image from CIE LUV space to CIE XYZ space.

Parameters:
luvtorch.Tensor

An image in CIE LUV space with shape (*, 3, H, W).

rgb_specRGBSpec, default=’srgb’

The name of RGB specification. The argument is case-insensitive.

whiteStandardIlluminants, default=’D65’

Reference white point for the rgb to xyz conversion. The input is case-insensitive.

obs{2, ‘2’, 10, ‘10’}, default=10

Degree of the standard observer (2° or 10°).

ret_matrixbool, default=False

If false, only the image is returned. If true, also returns the transformation matrix.

Returns:
xyztorch.Tensor

An image in CIE XYZ space with the shape (*, 3, H, W).

mattorch.Tensor

A transformation matrix used to convert RGB to CIE XYZ. mat is returned only if ret_matrix is true.

imgtools.color.rgb_to_luv(rgb: Tensor, rgb_spec: str = 'srgb', white: str = 'D65', obs: str | int = 10, ret_matrix: bool = False) Tensor

Converts an image from RGB space to CIE LUV space.

The input is assumed to be in the range of [0, 1]. If rgb_spec is a tensor, then the input rgb is assumed to be linear RGB.

Parameters:
rgbtorch.Tensor

An RGB image in the range of [0, 1] with shape (*, 3, H, W).

rgb_specRGBSpec, default=’srgb’

The name of RGB specification. The argument is case-insensitive.

whiteStandardIlluminants, default=’D65’

Reference white point for the rgb to xyz conversion. The input is case-insensitive.

obs{2, ‘2’, 10, ‘10’}, default=10

Degree of the standard observer (2° or 10°).

ret_matrixbool, default=False

If false, only the image is returned. If true, also returns the transformation matrix.

Returns:
luvtorch.Tensor

An image in CIE LUV space with the shape (*, 3, H, W).

mattorch.Tensor

A transformation matrix used to convert RGB to CIE XYZ. mat is returned only if ret_matrix is true.

imgtools.color.xyz_to_luv(xyz: Tensor, rgb_spec: str = 'srgb', white: str = 'D65', obs: str | int = 10, ret_matrix: bool = False) Tensor | tuple[Tensor, Tensor]

Converts an image from CIE XYZ space to CIE LUV space.

Parameters:
xyztorch.Tensor

An image in CIE XYZ space with shape (*, 3, H, W).

rgb_specRGBSpec, default=’srgb’

The name of RGB specification. The argument is case-insensitive.

whiteStandardIlluminants, default=’D65’

Reference white point for the rgb to xyz conversion. The input is case-insensitive.

obs{2, ‘2’, 10, ‘10’}, default=10

Degree of the standard observer (2° or 10°).

ret_matrixbool, default=False

If false, only the image is returned. If true, also returns the transformation matrix.

Returns:
luvtorch.Tensor

An image in CIE LUV space with the shape (*, 3, H, W).

mattorch.Tensor

A transformation matrix used to convert RGB to CIE XYZ. mat is returned only if ret_matrix is true.

imgtools.color.get_rgb_model(rgb_spec: str)

Returns a dict containing informations about a RGB specification.

Parameters:
rgb_specRGBSpec

Name of the RGB specification, such as sRGB, displayP3, etc. The input is case-insensitive.

Returns:
RGBModel

Dict with the folloing keys: - name: The name of the color space. - r: (x, y) value of red in xyY space. - g: (x, y) value of green in xyY space. - b: (x, y) value of blue in xyY space. - w: The name of the white point.

imgtools.color.get_rgb_names() tuple[str, ...]

Names of RGB models, such as srgb or displayp3.

Returns:
tuple[str, …]

Names of RGB models.

imgtools.color.get_rgb_to_xyz_matrix(rgb_spec: str, white: str, obs: int | str = 10, dtype: dtype = torch.float32, device: device | str = 'cpu') Tensor

Evaluate the matrix for converting RGB to CIE XYZ by the given RGB model, white point, and degree of observer.

Parameters:
rgb_specRGBSpec, default=’srgb’

The name of RGB specification. The argument is case-insensitive.

whiteStandardIlluminants, default=’D65’

White point. The input is case-insensitive.

obs{2, ‘2’, 10, ‘10’}, default=10

The degree of oberver

dtypetorch.dtype, default=torch.float32

The data type of the tensor. Must be a floating point.

device: torch.device | str, default=’cpu’

The device of the tensor.

Returns:
mattorch.Tensor

A transformation matrix used to convert RGB to CIE XYZ.

Raises:
ValueError

When dtype is not a floating point.

imgtools.color.get_white_point(white: str, obs: str | int = 10)

Returns a dictionary that contains name, x, y, CCT, and degree of observer of the standard illuminant.

Parameters:
whiteStandardIlluminants

Name of the standard illuminant, such as D65, D50, and F1-F12. The input is case-insensitive.

obs{2, ‘2’, 10, ‘10’}, default=10

Degree of observer. None and invalid value will be regarded as 10 degree. The input is case-insensitive.

Returns:
WhitePoint

Dict with the folloing keys: - name: The name of the standard illuminant. - xy: The (x, y) values in xyY space. - cct: The correlated color temperature. - obs: The degree of observer.

imgtools.color.get_white_point_names() tuple[str, ...]

Support standard illuminants.

Returns:
tuple[str, …]

Names of standard illuminants.

imgtools.color.get_xyz_to_rgb_matrix(rgb_spec: str, white: str, obs: str | int = 10, dtype: dtype = torch.float32, device: device | str = 'cpu') Tensor

Evaluate the matrix for converting CIE XYZ to RGB by the given RGB model, white point, and degree of observer.

Parameters:
rgb_specRGBSpec, default=’srgb’

The name of RGB specification. The argument is case-insensitive.

whiteStandardIlluminants, default=’D65’

White point. The input is case-insensitive.

obs{2, ‘2’, 10, ‘10’}, default=10

The degree of oberver.

dtypetorch.dtype, default=torch.float32

The data type of the tensor. Must be a floating point.

device: torch.device | str, default=’cpu’

The device of the tensor.

Returns:
mattorch.Tensor

A transformation matrix used to convert CIE XYZ to RGB.

Raises:
ValueError

When dtype is not a floating point.

imgtools.color.normalize_xyz(xyz: Tensor, rgb_spec: str = 'srgb', white: str = 'D65', obs: str | int = 10) Tensor

Normalize the image in CIE XYZ to [0, 1] by evaluting xyz / rgb_to_xyz(white_rgb) and clips to [0, 1].

Parameters:
xyztorch.Tensor

An image in CIE XYZ space with shape (*, 3, H, W).

rgb_specRGBSpec, default=’srgb’

The name of RGB specification. The argument is case-insensitive.

whiteStandardIlluminants, default=’D65’

White point. The input is case-insensitive.

obs{2, ‘2’, 10, ‘10’}, default=10

The degree of oberver.

imgtools.color.rgb_to_xyz(rgb: Tensor, rgb_spec: str = 'srgb', white: str = 'D65', obs: str | int = 10, ret_matrix: bool = False) Tensor | tuple[Tensor, Tensor]

Converts an image from RGB space to CIE XYZ space.

The input is assumed to be in the range of [0, 1]. If rgb_spec is a tensor, then the input rgb is assumed to be linear RGB.

The minimum of channels of XYZ is 0, and the maxima of channels depend on the RGB model and the white point (Y channel always 1).

Parameters:
rgbtorch.Tensor

An RGB image in the range of [0, 1] with shape (*, 3, H, W).

rgb_specRGBSpec, default=’srgb’

The name of RGB specification. The argument is case-insensitive.

whiteStandardIlluminants, default=’D65’

Reference white point for the rgb to xyz conversion. The input is case-insensitive.

obs{2, ‘2’, 10, ‘10’}, default=10

Degree of the standard observer (2° or 10°).

ret_matrixbool, default=False

If false, only the image is returned. If true, also returns the transformation matrix.

Returns:
xyztorch.Tensor

An image in CIE XYZ space with the shape (*, 3, H, W).

mattorch.Tensor

A transformation matrix used to convert RGB to CIE XYZ. mat is returned only if ret_matrix is true.

imgtools.color.unnormalize_xyz(xyz: Tensor, rgb_spec: str = 'srgb', white: str = 'D65', obs: str | int = 10) Tensor

The inverse function of normalize_xyz.

Parameters:
xyztorch.Tensor

An image in CIE XYZ space with shape (*, 3, H, W).

rgb_specRGBSpec, default=’srgb’

The name of RGB specification. The argument is case-insensitive.

whiteStandardIlluminants, default=’D65’

White point. The input is case-insensitive.

obs{2, ‘2’, 10, ‘10’}, default=10

The degree of oberver.

inplacebool, default=False

In-place operation or not.

imgtools.color.xyz_to_rgb(xyz: Tensor, rgb_spec: str = 'srgb', white: str = 'D65', obs: str | int = 10, ret_matrix: bool = False) Tensor | tuple[Tensor, Tensor]

Converts an image from CIE XYZ space to RGB space.

Parameters:
xyztorch.Tensor

An image in CIE XYZ space with shape (*, 3, H, W).

rgb_specRGBSpec, default=’srgb’

The name of RGB specification. The argument is case-insensitive.

whiteStandardIlluminants, default=’D65’

Reference white point for the rgb to xyz conversion. The input is case-insensitive.

obs{2, ‘2’, 10, ‘10’}, default=10

Degree of the standard observer (2° or 10°).

ret_matrixbool, default=False

If false, only the image is returned. If true, also returns the transformation matrix.

Returns:
rgbtorch.Tensor

An RGB image in the range of [0, 1] with the shape (*, 3, H, W).

mattorch.Tensor

A transformation matrix used to convert CIE XYZ to RGB. mat is returned only if ret_matrix is true.

imgtools.color.gray_to_rgb(gray: Tensor) Tensor

Converts an image from grayscale to rgb space.

Parameters:
graytorch.Tensor

An grayscale image with shape (*, 1, H, W).

Returns:
torch.Tensor

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

imgtools.color.rgb_to_gray(rgb: Tensor) Tensor

Converts an image from RGB space to grayscale.

Parameters:
rgbtorch.Tensor

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

Returns:
torch.Tensor

An grayscale image with shape (*, 1, H, W). The maximum is the same as the input.

imgtools.color.hed_to_rgb(hed: Tensor) Tensor

Converts an image from HED space [1] to RGB space.

Parameters:
hextorch.Tensor

An image in HED space with shape (*, 3, H, W).

Returns:
torch.Tensor

An image in RGB space in the range of [0, 1] with shape (*, 3, H, W).

References

[1] A. C. Ruifrok and D. A. Johnston,

“Quantification of histochemical staining by color deconvolution,” Analytical and quantitative cytology and histology / the International Academy of Cytology [and] American Society of Cytology, vol. 23, no. 4, pp. 291-9, Aug. 2001.

imgtools.color.rgb_to_hed(rgb: Tensor) Tensor

Converts an image from RGB space to HED space [1].

Parameters:
rgbtorch.Tensor

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

Returns:
torch.Tensor

An image in HED space. The the coefficients of the transformation matrix is scaled. Hence the maximum is the same as the input.

References

[1] A. C. Ruifrok and D. A. Johnston,

“Quantification of histochemical staining by color deconvolution,” Analytical and quantitative cytology and histology / the International Academy of Cytology [and] American Society of Cytology, vol. 23, no. 4, pp. 291-9, Aug. 2001.

imgtools.color.hsi_to_rgb(hsi: Tensor) Tensor

Converts an image from HSI space to RGB space.

Parameters:
hsitorch.Tensor

An image in HSI space with shape (*, 3, H, W).

Returns:
torch.Tensor

An RGB image in the range of [0, 1] with the shape (*, 3, H, W).

imgtools.color.rgb_to_hsi(rgb: Tensor) Tensor

Converts an image from RGB space to HSI space.

The input is assumed to be in the range of [0, 1].

Parameters:
rgbtorch.Tensor

An RGB image in the range of [0, 1] with shape (*, 3, H, W).

Returns:
torch.Tensor

An image in HSI space with shape (*, 3, H, W). The H channel values are in the range [0, 360), S and L are in the range of [0, 1].

imgtools.color.hsl_to_rgb(hsl: Tensor) Tensor

Converts an image from HSL space to RGB space.

Parameters:
svnp.ndarray | torch.Tensor

An image in HSL space with shape (*, 3, H, W).

Returns:
torch.Tensor

An RGB image in the range of [0, 1] with the shape (*, 3, H, W).

imgtools.color.rgb_to_hsl(rgb: Tensor) Tensor

Converts an image from RGB space to HSL space.

The input is assumed to be in the range of [0, 1].

Parameters:
rgbnp.ndarray | torch.Tensor

An RGB image in the range of [0, 1] with shape (*, 3, H, W).

Returns:
torch.Tensor

An image in HSL space with shape (*, 3, H, W). The H channel values are in the range [0, 360), S and L are in the range of [0, 1].

imgtools.color.hsv_to_rgb(hsv: Tensor) Tensor

Converts an image from HSV space to RGB space.

Parameters:
hsvtorch.Tensor

An image in HSV space with shape (*, 3, H, W).

Returns:
torch.Tensor

An RGB image in the range of [0, 1] with the shape (*, 3, H, W).

imgtools.color.rgb_to_hsv(rgb: Tensor) Tensor

Converts an image from RGB space to HSV space.

The input is assumed to be in the range of [0, 1].

Parameters:
rgbtorch.Tensor

An RGB image in the range of [0, 1] with shape (*, 3, H, W).

Returns:
torch.Tensor

An image in HSV space with shape (*, 3, H, W). The H channel values are in the range [0, 360), S and V are in the range of [0, 1].

imgtools.color.hwb_to_rgb(hwb: Tensor) Tensor

Converts an image from HWB space to RGB space.

Parameters:
hwbtorch.Tensor

An image in HWB space with shape (*, 3, H, W).

Returns:
torch.Tensor

An RGB image in the range of [0, 1] with the shape (*, 3, H, W).

imgtools.color.rgb_to_hwb(rgb: Tensor) Tensor

Converts an image from RGB space to HWB space.

The input is assumed to be in the range of [0, 1].

Parameters:
rgbtorch.Tensor

An RGB image in the range of [0, 1] with shape (*, 3, H, W).

Returns:
torch.Tensor

An image in HWB space with shape (*, 3, H, W). The H channel values are in the range [0, 360), W and B are in the range of [0, 1].

imgtools.color.get_chromatic_adaptation() tuple[str, ...]

Returns the support chromatic adaptation methods.

Returns:
list[str]

A list of chromatic adaptation names.

imgtools.color.get_lms_to_xyz_matrix(method: str = 'bradford', dtype: dtype = torch.float32, device: device | str = 'cpu')

Returns a transformation matrix for the conversion from LMS space to CIE XYZ space.

Parameters:
methodCATMethod, default=’bradford’

The method of conversion. The argument is case-insensitive.

dtypetorch.dtype, default=torch.float32

The data type of the tensor. Must be a floating point.

device: torch.device | str, default=’cpu’

The device of the tensor.

Returns:
torch.Tensor

The transformation matrix with shape (3, 3).

Raises:
ValueError

When dtype is not a floating point.

imgtools.color.get_xyz_to_lms_matrix(method: str = 'bradford', dtype: dtype = torch.float32, device: device | str = 'cpu')

Returns a transformation matrix for the conversion from CIE XYZ space to LMS space.

Parameters:
methodCATMethod, default=’bradford’

The method of conversion. The argument is case-insensitive. Check valid values by calling get_chromatic_adaptation().

dtypetorch.dtype, default=torch.float32

The data type of the tensor. Must be a floating point.

device: torch.device | str, default=’cpu’

The device of the tensor.

Returns:
torch.Tensor

The transformation matrix with shape (3, 3).

Raises:
ValueError

When dtype is not a floating point.

imgtools.color.lms_to_xyz(lms: Tensor, method: str = 'bradford', ret_matrix: bool = False)

Converts an image from LMS space to CIE XYZ space.

Parameters:
xyztorch.Tensor

An image in LMS space with shape (*, 3, H, W).

methodCATMethod, default=’bradford’

The method of conversion. The argument is case-insensitive.

ret_matrixbool, default=False

If false, only the image is returned. If true, also returns the transformation matrix.

Returns:
xyztorch.Tensor

An image in CIE XYZ space with the shape (*, 3, H, W).

mattorch.Tensor

A transformation matrix used to convert LMS to CIE XYZ. mat is returned only if ret_matrix is true.

imgtools.color.xyz_to_lms(xyz: Tensor, method: str = 'bradford', ret_matrix: bool = False) Tensor | tuple[Tensor, Tensor]

Converts an image from CIE XYZ space to LMS space.

Parameters:
xyztorch.Tensor

An image in CIE XYZ space with shape (*, 3, H, W).

methodCATMethod, default=’bradford’

The method of conversion. The argument is case-insensitive.

ret_matrixbool, default=False

If false, only the image is returned. If true, also returns the transformation matrix.

Returns:
lmstorch.Tensor

An image in LMS space with the shape (*, 3, H, W).

mattorch.Tensor

A transformation matrix used to convert CIE XYZ to LMS. mat is returned only if ret_matrix is true.

imgtools.color.rgb_to_yuv(rgb: Tensor) Tensor

Converts an image from RGB space to YUV space.

The input is assumed to be in the range of [0, 1].

Parameters:
rgbtorch.Tensor

An RGB imag in the range of [0, 1] with shape (*, 3, H, W).

Returns:
torch.Tensor

An image in YUV space with shape (*, 3, H, W). The range of Y is [0, 1] and the range of U and V are [-0.5, 0.5].

imgtools.color.yuv_to_rgb(yuv: Tensor) Tensor

Converts an image from YUV space to RGB space.

The input is assumed to be in the range of [0, 1] (for Y channel) and [-0.5, 0.5] (for U and V channels). The output will be clip to [0, 1].

Parameters:
yuvtorch.Tensor

An image in YUV space with shape (*, 3, H, W).

Returns:
torch.Tensor

An RGB image in the range of [0, 1] with the shape (*, 3, H, W).