# 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) The normalized version of the input image (keeping the same dimension and shape) 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}$$.

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). The score of the image cleaning algorithm for the given image. 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).
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). The score of the image cleaning algorithm for the given image. 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.

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). The score of the image cleaning algorithm for the given image. float

References

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.

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 $$x$$;
• $$\scriptstyle\mu_y$$ the average of $$y$$;
• $$\scriptstyle\sigma_x^2$$ the variance of $$x$$;
• $$\scriptstyle\sigma_y^2$$ the variance of $$y$$;
• $$\sigma_{xy}$$ the covariance of $$x$$ and $$y$$;
• $$c_1 = (k_1L)^2$$, $$c_2 = (k_2L)^2$$ two variables to stabilize the division with weak denominator;
• $$L$$ the dynamic range of the pixel-values (typically this is $$2^{\#bits\ per\ pixel}-1$$);
• $$k_1 = 0.01$$ and $$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). The score of the image cleaning algorithm for the given image. float

References

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