SharpnessIndex#
- class deepinv.loss.metric.SharpnessIndex(periodic_component=True, dequantize=True, **kwargs)[source]#
Bases:
MetricNo-reference sharpness index metric for 2D images.
Measures how sharp an image is, defined as
\[\text{SI}(x) = -\log \Phi \left( \frac{\mathbb{E}_{\omega} \{ \text{TV}(\omega * x)\} - \text{TV}(x) }{\sqrt{\mathbb{V}_{\omega} \{ \text{TV}(\omega * x) \} } } \right)\]where \(\Phi\) is the CDF of a standard Gaussian distribution, \(\text{TV}\) is the total variation, and \(\omega \sim \mathcal{N}(0, I)\) is a Gaussian white noise distribution.
Higher values indicate sharper images.
The metric is used to introduced by Blanchet and Moisan [10]. We use the fast implementation presented by Leclaire and Moisan [60].
Adapted from MATLAB implementation in https://helios2.mi.parisdescartes.fr/~moisan/sharpness/.
Default mode computing the periodic component and dequantizing should be used, unless you want to work on very specific images that are naturally periodic or not quantized (see Leclaire and Moisan [60]).
- Parameters:
periodic_component (bool) β if
True(default), compute the periodic component of the image before computing the metric.dequantize (bool) β if
True(default), perform image dequantization by (1/2, 1/2) translation in Fourier domain before computing the metric.complex_abs (bool) β perform complex magnitude before passing data to metric function. If
True, the data must either be of complex dtype or have size 2 in the channel dimension (usually the second dimension after batch).reduction (str) β a method to reduce metric score over individual batch scores.
mean: takes the mean,sumtakes the sum,noneor None no reduction will be applied (default).norm_inputs (str) β normalize images before passing to metric.
l2normalizes by \(\ell_2\) spatial norm,min_maxnormalizes by min and max of each input.check_input_range (bool) β if True,
pyiqawill raise error if inputs arenβt in the appropriate range[0, 1].center_crop (int, tuple[int], None) β If not
None(default), center crop the tensor(s) before computing the metrics. If anintis provided, the cropping is applied equally on all spatial dimensions (by default, all dimensions except the first two). Iftupleofint, cropping is performed over the lastlen(center_crop)dimensions. If positive values are provided, a standard center crop is applied. If negative (or zero) values are passed, cropping will be done by removingcenter_croppixels from the borders (useful when tensors vary in size across the dataset).
- Example:
>>> from deepinv.loss.metric import SharpnessIndex >>> m = SharpnessIndex() >>> x_net = torch.randn(2, 3, 16, 16) # batch of 2 RGB images >>> m(x_net).shape torch.Size([2])
- static dequant(u)[source]#
Image dequantization via (1/2, 1/2) translation in Fourier domain.
Adapted from MATLAB implementation in https://helios2.mi.parisdescartes.fr/~moisan/sharpness/.
- Parameters:
u (torch.Tensor) β (B, C, H, W) tensor
- Returns:
(:class:torch.Tensor) dequantized image (B, C, H, W)
- Return type:
- static logerfc(x)[source]#
Compute
log(erfc(x))with asymptotic expansion for largex.Adapted from MATLAB implementation in https://helios2.mi.parisdescartes.fr/~moisan/sharpness/.
- Parameters:
x (torch.Tensor) β
(B, C, H, W)tensor- Returns:
(B,)tensor of logarithmic value ofx- Return type:
- metric(x_net, *args, **kwargs)[source]#
Compute sharpness index metric for a batch of images.
- Parameters:
x_net β (B, C, H, W) input tensors with C=1 or 3 channels.
- Returns:
(B,) tensor of sharpness index values for each image in the batch
- static per_decomp(u)[source]#
Periodic + smooth decomposition of a 2D image.
Adapted from MATLAB implementation in https://helios2.mi.parisdescartes.fr/~moisan/sharpness/.
- Parameters:
u (torch.Tensor) β (B, C, H, W) tensor
- Returns:
p: periodic component minus smooth component (B, C, H, W)
- Return type: