piqa.mdsi#
Mean Deviation Similarity Index (MDSI)
This module implements the MDSI in PyTorch.
Original
https://www.mathworks.com/matlabcentral/fileexchange/59809-mdsi-ref-dist-combmethod
References
Functions#
Returns the MDSI between \(x\) and \(y\), without color space conversion and downsampling. |
Classes#
Measures the MDSI between an input and a target. |
Descriptions#
- piqa.mdsi.mdsi(x, y, kernel, combination='sum', value_range=1.0, c1=0.0021530180699730873, c2=0.0008458285274894271, c3=0.008458285274894272, alpha=0.6, beta=0.1, gamma=0.2, rho=1.0, q=0.25, o=0.25)#
Returns the MDSI between \(x\) and \(y\), without color space conversion and downsampling.
- Parameters:
x (Tensor) – An input tensor, \((N, 3, H, W)\).
y (Tensor) – A target tensor, \((N, 3, H, W)\).
kernel (Tensor) – A gradient kernel, \((2, 1, K, K)\).
combination (str) – Specifies the scheme to combine the gradient and chromaticity similarities (GS, CS):
'sum'
or'prod'
.value_range (float) – The value range \(L\) of the inputs (usually 1 or 255).
Note
For the remaining arguments, refer to Nafchi et al. (2016).
- Returns:
The MDSI vector, \((N,)\).
- Return type:
Example
>>> x = torch.rand(5, 1, 256, 256) >>> y = torch.rand(5, 1, 256, 256) >>> kernel = gradient_kernel(prewitt_kernel()) >>> l = mdsi(x, y, kernel) >>> l.shape torch.Size([5])
- class piqa.mdsi.MDSI(downsample=True, kernel=None, reduction='mean', **kwargs)#
Measures the MDSI between an input and a target.
Before applying
mdsi
, the input and target are converted from RBG to LHM and downsampled to a 256-ish resolution.- Parameters:
Example
>>> criterion = MDSI() >>> x = torch.rand(5, 3, 256, 256, requires_grad=True) >>> y = torch.rand(5, 3, 256, 256) >>> l = criterion(x, y) >>> l.shape torch.Size([]) >>> l.backward()