SharpnessIndex#

class deepinv.loss.metric.SharpnessIndex(periodic_component=True, dequantize=True, **kwargs)[source]#

Bases: Metric

No-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, sum takes the sum, none or None no reduction will be applied (default).

  • norm_inputs (str) – normalize images before passing to metric. l2 normalizes by \(\ell_2\) spatial norm, min_max normalizes by min and max of each input.

  • check_input_range (bool) – if True, pyiqa will 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 an int is provided, the cropping is applied equally on all spatial dimensions (by default, all dimensions except the first two). If tuple of int, cropping is performed over the last len(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 removing center_crop pixels 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:

Tensor

static logerfc(x)[source]#

Compute log(erfc(x)) with asymptotic expansion for large x.

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 of x

Return type:

Tensor

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:

Tensor

Examples using SharpnessIndex:#

Blind deblurring with kernel estimation network

Blind deblurring with kernel estimation network