magni.imaging.evaluation module¶
Module providing functions for evaluation of image reconstruction quality.
Routine listings¶
- calculate_mse(x_org, x_recons)
- Function to calcualte Mean Squared Error (MSE).
- calculate_psnr(x_org, x_recons, peak)
- Function to calculate Peak Signal to Noise Ratio (PSNR).
- calculate_retained_energy(x_org, x_recons)
- Function to calculate the percentage of energy retained in reconstruction.
-
magni.imaging.evaluation.
calculate_mse
(x_org, x_recons)[source]¶ Calculate Mean Squared Error (MSE) between x_recons and x_org.
Parameters: - x_org (ndarray) – Array of original values.
- x_recons (ndarray) – Array of reconstruction values.
Returns: mse (float) – Mean Squared Error (MSE).
Notes
The Mean Squared Error (MSE) is calculated as:
\[\frac{1}{N} \cdot \sum(x_{org} - x_{recons})^2\]where N is the number of entries in x_org.
Examples
For example,
>>> import numpy as np >>> from magni.imaging.evaluation import calculate_mse >>> x_org = np.arange(4).reshape(2, 2) >>> x_recons = np.ones((2,2)) >>> print('{:.2f}'.format(calculate_mse(x_org, x_recons))) 1.50
-
magni.imaging.evaluation.
calculate_psnr
(x_org, x_recons, peak)[source]¶ Calculate Peak Signal to Noise Ratio (PSNR) between x_recons and x_org.
Parameters: - x_org (ndarray) – Array of original values.
- x_recons (ndarray) – Array of reconstruction values.
- peak (int or float) – Peak value.
Returns: psnr (float) – Peak Signal to Noise Ratio (PSNR) in dB.
Notes
The PSNR is as calculated as
\[10 \cdot \log_{10}\left(\frac{peak^2}{ 1/N \cdot \sum(x_{org} - x_{recons})^2}\right)\]where N is the number of entries in x_org.
If \(|x_{org} - x_{recons}| <= (10^{-8} + 1^{-5} * |x_{recons}|)\) then
np.inf
is returned.Examples
For example,
>>> import numpy as np >>> from magni.imaging.evaluation import calculate_psnr >>> x_org = np.arange(4).reshape(2, 2) >>> x_recons = np.ones((2,2)) >>> peak = 3 >>> print('{:.2f}'.format(calculate_psnr(x_org, x_recons, peak))) 7.78
-
magni.imaging.evaluation.
calculate_retained_energy
(x_org, x_recons)[source]¶ Calculate percentage of energy retained in reconstruction.
Parameters: - x_org (ndarray) – Array of original values (must not be all zeros).
- x_recons (ndarray) – Array of reconstruction values.
Returns: energy (float) – Percentage of retained energy in reconstruction.
Notes
The retained energy is as calculated as
\[\frac{\sum x_{recons}^2}{\sum x_{org}^2} \cdot 100\%\]Examples
For example,
>>> import numpy as np >>> from magni.imaging.evaluation import calculate_retained_energy >>> x_org = np.arange(4).reshape(2, 2) >>> x_recons = np.ones((2,2)) >>> print('{:.2f}'.format(calculate_retained_energy(x_org, x_recons))) 28.57