LION.metrics.haarpsi¶
Classes
|
HaarPSI: the Haar wavelet-based perceptual similarity index, for (potentially) batched pytorch tensors, used like LION's PSNR and SSIM. |
- class LION.metrics.haarpsi.HAARPsi(preprocess_with_subsampling=True, C=30.0, a=4.2)[source]¶
Bases:
ModuleHaarPSI: the Haar wavelet-based perceptual similarity index, for (potentially) batched pytorch tensors, used like LION’s PSNR and SSIM.
Reisenhofer, Bosse, Kutyniok and Wiegand, “A Haar wavelet-based perceptual similarity index for image quality assessment”, Signal Processing: Image Communication 61 (2018). PyTorch implementation by Sören Dittmer and Clemens Karner (through project FWF T1307-N/Anna Breger), from the TensorFlow implementation by David Neumann and the MATLAB one by Rafael Reisenhofer. It matches
piq.haarpsifor images in [0, data_range].preprocess_with_subsampling: subsample the images by 2 first, as in the paper (True);C,a: the algorithm’s constants, found experimentally by HaarPSI’s authors (30 and 4.2, for images in [0, 255]).Initialize internal Module state, shared by both nn.Module and ScriptModule.
- higher_is_better = True¶
- forward(x, target, reduce=None, batched=True, data_range=None)[source]¶
The HaarPSI of
xagainsttarget(the same shape), in [0, 1], 1 for identical images: one per sample, or their mean ifreduceis “mean”.batched:xis (B, C, H, W) or (B, H, W), else (C, H, W) or (H, W); C is 1 (grayscale) or 3 (RGB).data_range: images are in [0, data_range] (e.g. 1), as inpiq.haarpsi; None: each pair is mapped by its target’s minimum and range to a target in [0, 1], like the range PSNR and SSIM use. Images may have values outside the range (e.g. noisy reconstructions).
- maps(x, target, batched=True, data_range=None)[source]¶
HaarPSI with its local similarity maps and weights.
Same arguments as
forward. Returns(score, local_similarities, weights): score has shape (B,), the others (B, n_channels, H, W), with H and W halved if subsampling and n_channels 2 for grayscale or 3 for colour images (always batched).