benchmark.metrics.refbased

pywi.benchmark.metrics.refbased.normalize_array(array)[source]

Normalize the given array such that its values fit between 0.0 and 1.0.

It applies

\[\text{normalize}(\boldsymbol{S}) = \frac{ \boldsymbol{S} - \text{min}(\boldsymbol{S}) }{ \text{max}(\boldsymbol{S}) - \text{min}(\boldsymbol{S}) }\]

where \(\boldsymbol{S}\) is the input array (an image).

Parameters:image (Numpy array) – The image to normalize (whatever its shape)
Returns:The normalized version of the input image (keeping the same dimension and shape)
Return type:Numpy array
pywi.benchmark.metrics.refbased.mse(image, reference_image)[source]

Compute the score of image regarding reference_image with the Mean-Squared Error (MSE) metric.

It applies

\[\text{MSE}(\hat{\boldsymbol{S}}, \boldsymbol{S}^*) = \left\langle \left( \hat{\boldsymbol{S}} - \boldsymbol{S}^* \right)^{\circ 2} \right\rangle\]

with:

  • \(\hat{\boldsymbol{S}}\) the algorithm’s output image (i.e. the cleaned image);
  • \(\boldsymbol{S}^*\) the reference image (i.e. the clean image);
  • \(\langle \boldsymbol{S} \rangle\) the average of matrix \(\boldsymbol{S}\);
  • \(\boldsymbol{S}^{\circ 2}\) the Hadamar power (i.e. the element wise square) of matrix \(\boldsymbol{S}\).

See http://scikit-image.org/docs/dev/api/skimage.measure.html#compare-mse for more information.

Note

This function is not well-suited to high dynamic range images handled with this project (errors are correlated with energy levels).

Parameters:
  • image (2D ndarray) – The cleaned image returned by the image cleanning algorithm to assess.
  • reference_image (2D ndarray) – The actual clean image (the best result that can be expected for the image cleaning algorithm).
Returns:

The score of the image cleaning algorithm for the given image.

Return type:

float

pywi.benchmark.metrics.refbased.nrmse(image, reference_image)[source]

Compute the score of image regarding reference_image with the Normalized Root Mean-Squared Error (NRMSE) metric.

It applies

\[\text{NRMSE}(\hat{\boldsymbol{S}}, \boldsymbol{S}^*) = \frac{\sqrt{\text{MSE}}}{\sqrt{ \left\langle \hat{\boldsymbol{S}} \circ \boldsymbol{S}^* \right\rangle }}\]

with:

  • \(\hat{\boldsymbol{S}}\) the algorithm’s output image (i.e. the cleaned image);
  • \(\boldsymbol{S}^*\) the reference image (i.e. the clean image);
  • \(\langle \boldsymbol{S} \rangle\) the average of matrix \(\boldsymbol{S}\);
  • \(\circ\) the Hadamar product (i.e. the element wise product operator).

See http://scikit-image.org/docs/dev/api/skimage.measure.html#compare-nrmse and https://en.wikipedia.org/wiki/Root-mean-square_deviation for more information.

Parameters:
  • image (2D ndarray) – The cleaned image returned by the image cleanning algorithm to assess.
  • reference_image (2D ndarray) – The actual clean image (the best result that can be expected for the image cleaning algorithm).
Returns:

The score of the image cleaning algorithm for the given image.

Return type:

float

pywi.benchmark.metrics.refbased.psnr(image, reference_image)[source]

Compute the score of image regarding reference_image with the Peak Signal-to-Noise Ratio (PSNR) metric.

See [5] and [6] for more information.

Parameters:
  • image (2D ndarray) – The cleaned image returned by the image cleanning algorithm to assess.
  • reference_image (2D ndarray) – The actual clean image (the best result that can be expected for the image cleaning algorithm).
Returns:

The score of the image cleaning algorithm for the given image.

Return type:

float

References

[5]http://scikit-image.org/docs/dev/api/skimage.measure.html#skimage.measure.compare_psnr
[6]https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio
pywi.benchmark.metrics.refbased.ssim(image, reference_image)[source]

Compute the score of image regarding reference_image with the Structural Similarity Index Measure (SSIM) metric.

See [1], [2], [3] and [4] for more information.

The SSIM index is calculated on various windows of an image. The measure between two windows \(x\) and \(y\) of common size \(N.N\) is:

\[\hbox{SSIM}(x,y) = \frac{(2\mu_x\mu_y + c_1)(2\sigma_{xy} + c_2)}{(\mu_x^2 + \mu_y^2 + c_1)(\sigma_x^2 + \sigma_y^2 + c_2)}\]

with:

  • \(\scriptstyle\mu_x\) the average of \(\scriptstyle x\);
  • \(\scriptstyle\mu_y\) the average of \(\scriptstyle y\);
  • \(\scriptstyle\sigma_x^2\) the variance of \(\scriptstyle x\);
  • \(\scriptstyle\sigma_y^2\) the variance of \(\scriptstyle y\);
  • \(\scriptstyle \sigma_{xy}\) the covariance of \(\scriptstyle x\) and \(\scriptstyle y\);
  • \(\scriptstyle c_1 = (k_1L)^2\), \(\scriptstyle c_2 = (k_2L)^2\) two variables to stabilize the division with weak denominator;
  • \(\scriptstyle L\) the dynamic range of the pixel-values (typically this is \(\scriptstyle 2^{\#bits\ per\ pixel}-1\));
  • \(\scriptstyle k_1 = 0.01\) and \(\scriptstyle k_2 = 0.03\) by default.

The SSIM index satisfies the condition of symmetry:

\[\text{SSIM}(x, y) = \text{SSIM}(y, x)\]
Parameters:
  • image (2D ndarray) – The cleaned image returned by the image cleanning algorithm to assess.
  • reference_image (2D ndarray) – The actual clean image (the best result that can be expected for the image cleaning algorithm).
Returns:

The score of the image cleaning algorithm for the given image.

Return type:

float

References

[1]Wang, Z., Bovik, A. C., Sheikh, H. R., & Simoncelli, E. P. (2004). Image quality assessment: From error visibility to structural similarity. IEEE Transactions on Image Processing, 13, 600-612. https://ece.uwaterloo.ca/~z70wang/publications/ssim.pdf, DOI:10.1.1.11.2477
[2]Avanaki, A. N. (2009). Exact global histogram specification optimized for structural similarity. Optical Review, 16, 613-621. http://arxiv.org/abs/0901.0065, DOI:10.1007/s10043-009-0119-z
[3]http://scikit-image.org/docs/dev/api/skimage.measure.html#compare-ssim
[4]https://en.wikipedia.org/wiki/Structural_similarity