piqa.utils.color#

Color space conversion tools

Functions#

color_conv

Returns the color convolution of \(x\) with the kernel weight.

rgb_to_xyz

Converts from sRGB to (CIE) XYZ.

xyz_to_lab

Converts from (CIE) XYZ to (CIE) LAB.

Classes#

ColorConv

Color convolution module.

ImageNetNorm

Normalizes channels with respect to ImageNet's mean and standard deviation.

Descriptions#

piqa.utils.color.color_conv(x, weight, bias=None)#

Returns the color convolution of \(x\) with the kernel weight.

Parameters:
  • x (Tensor) – A tensor, \((N, C, *)\).

  • weight (Tensor) – A weight kernel, \((C', C)\).

  • bias (Tensor | None) – A bias vector, \((C',)\).

class piqa.utils.color.ColorConv(src, dst)#

Color convolution module.

Parameters:
  • src (str) – The source color space (e.g. 'RGB').

  • dst (str) – The destination color space (e.g. 'YIQ').

Example

>>> x = torch.rand(5, 3, 256, 256)
>>> conv = ColorConv('RGB', 'YIQ')
>>> y = conv(x)
>>> y.shape
torch.Size([5, 3, 256, 256])
piqa.utils.color.rgb_to_xyz(x, value_range=1.0)#

Converts from sRGB to (CIE) XYZ.

Wikipedia

https://wikipedia.org/wiki/SRGB

Parameters:

value_range (float) – The value range \(L\) of the inputs (usually 1 or 255).

piqa.utils.color.xyz_to_lab(x)#

Converts from (CIE) XYZ to (CIE) LAB.

Wikipedia

https://wikipedia.org/wiki/CIELAB_color_space

class piqa.utils.color.ImageNetNorm#

Normalizes channels with respect to ImageNet’s mean and standard deviation.

References

ImageNet: A large-scale hierarchical image database (Deng et al, 2009)

Example

>>> x = torch.rand(5, 3, 256, 256)
>>> normalize = ImageNetNorm()
>>> x = normalize(x)
>>> x.shape
torch.Size([5, 3, 256, 256])