pyiqa.utils.color_util¶
Color space conversion functions
Created by: https://github.com/photosynthesis-team/piq/blob/master/piq/functional/colour_conversion.py
Modified by: Chaofeng Chen (https://github.com/chaofengc)
Module Contents¶
- pyiqa.utils.color_util.to_y_channel(img: torch.Tensor, out_data_range: float = 1.0, color_space: str = 'yiq') torch.Tensor[source]¶
Change to Y channel :param image tensor: tensor with shape (N, 3, H, W) in range [0, 1].
- Returns:
Y channel of the input tensor
- Return type:
image tensor
- pyiqa.utils.color_util.rgb2ycbcr(x: torch.Tensor) torch.Tensor[source]¶
Convert a batch of RGB images to a batch of YCbCr images
It implements the ITU-R BT.601 conversion for standard-definition television. See more details in https://en.wikipedia.org/wiki/YCbCr#ITU-R_BT.601_conversion.
- Parameters:
x – Batch of images with shape (N, 3, H, W). RGB color space, range [0, 1].
- Returns:
Batch of images with shape (N, 3, H, W). YCbCr color space.
- pyiqa.utils.color_util.ycbcr2rgb(x: torch.Tensor) torch.Tensor[source]¶
Convert a batch of YCbCr images to a batch of RGB images
It implements the inversion of the above rgb2ycbcr function.
- Parameters:
x – Batch of images with shape (N, 3, H, W). YCbCr color space, range [0, 1].
- Returns:
Batch of images with shape (N, 3, H, W). RGB color space.
- pyiqa.utils.color_util.rgb2lmn(x: torch.Tensor) torch.Tensor[source]¶
Convert a batch of RGB images to a batch of LMN images
- Parameters:
x – Batch of images with shape (N, 3, H, W). RGB colour space.
- Returns:
Batch of images with shape (N, 3, H, W). LMN colour space.
- pyiqa.utils.color_util.rgb2xyz(x: torch.Tensor) torch.Tensor[source]¶
Convert a batch of RGB images to a batch of XYZ images
- Parameters:
x – Batch of images with shape (N, 3, H, W). RGB colour space.
- Returns:
Batch of images with shape (N, 3, H, W). XYZ colour space.
- pyiqa.utils.color_util.xyz2lab(x: torch.Tensor, illuminant: str = 'D50', observer: str = '2') torch.Tensor[source]¶
Convert a batch of XYZ images to a batch of LAB images
- Parameters:
x – Batch of images with shape (N, 3, H, W). XYZ colour space.
illuminant – {“A”, “D50”, “D55”, “D65”, “D75”, “E”}, optional. The name of the illuminant.
observer – {“2”, “10”}, optional. The aperture angle of the observer.
- Returns:
Batch of images with shape (N, 3, H, W). LAB colour space.
- pyiqa.utils.color_util.rgb2lab(x: torch.Tensor, data_range: int | float = 255) torch.Tensor[source]¶
Convert a batch of RGB images to a batch of LAB images
- Parameters:
x – Batch of images with shape (N, 3, H, W). RGB colour space.
data_range – dynamic range of the input image.
- Returns:
Batch of images with shape (N, 3, H, W). LAB colour space.
- pyiqa.utils.color_util.rgb2yiq(x: torch.Tensor) torch.Tensor[source]¶
Convert a batch of RGB images to a batch of YIQ images
- Parameters:
x – Batch of images with shape (N, 3, H, W). RGB colour space.
- Returns:
Batch of images with shape (N, 3, H, W). YIQ colour space.