piqa.haarpsi#

Haar Perceptual Similarity Index (HaarPSI)

This module implements the HaarPSI in PyTorch.

Original

https://github.com/rgcda/haarpsi

Wikipedia

https://wikipedia.org/wiki/Haar_wavelet

References

A Haar Wavelet-Based Perceptual Similarity Index for Image Quality Assessment (Reisenhofer et al., 2018)

Functions#

haarpsi

Returns the HaarPSI between \(x\) and \(y\), without color space conversion.

Classes#

HaarPSI

Measures the HaarPSI between an input and a target.

Descriptions#

piqa.haarpsi.haarpsi(x, y, n_kernels=3, value_range=1.0, c=0.000461361014994233, alpha=4.2)#

Returns the HaarPSI between \(x\) and \(y\), without color space conversion.

Parameters:
  • x (Tensor) – An input tensor, \((N, 3 \text{ or } 1, H, W)\).

  • y (Tensor) – A target tensor, \((N, 3 \text{ or } 1, H, W)\).

  • n_kernels (int) – The number of Haar wavelet kernels to use.

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

Note

For the remaining arguments, refer to Reisenhofer et al. (2018).

Returns:

The HaarPSI vector, \((N,)\).

Return type:

Tensor

Example

>>> x = torch.rand(5, 3, 256, 256)
>>> y = torch.rand(5, 3, 256, 256)
>>> l = haarpsi(x, y)
>>> l.shape
torch.Size([5])
class piqa.haarpsi.HaarPSI(chromatic=True, downsample=True, reduction='mean', **kwargs)#

Measures the HaarPSI between an input and a target.

Before applying haarpsi, the input and target are converted from RBG to Y(IQ) and downsampled by a factor 2.

Parameters:
  • chromatic (bool) – Whether to use the chromatic channels (IQ) or not.

  • downsample (bool) – Whether downsampling is enabled or not.

  • reduction (str) – Specifies the reduction to apply to the output: 'none', 'mean' or 'sum'.

  • kwargs – Keyword arguments passed to haarpsi.

Example

>>> criterion = HaarPSI()
>>> x = torch.rand(5, 3, 256, 256, requires_grad=True)
>>> y = torch.rand(5, 3, 256, 256)
>>> l = 1 - criterion(x, y)
>>> l.shape
torch.Size([])
>>> l.backward()
forward(x, y)#
Parameters:
  • x (Tensor) – An input tensor, \((N, 3, H, W)\).

  • y (Tensor) – A target tensor, \((N, 3, H, W)\).

Returns:

The HaarPSI vector, \((N,)\) or \(()\) depending on reduction.

Return type:

Tensor