Quality metrics¶
| Fact | Value |
|---|---|
| Also called | PSNR, SSIM, MSE, MAE, Image comparison |
| Status | Implemented and tested |
| Family | Utilities |
| Engine | Browser |
| Type | Nonlinear, statistical, image comparison |
| Output | Table |
| Operator shown as | estimator (exact) |
| Support radius | the whole image |
| Code | web/src/core/metrics/quality.ts, qualityMetrics |
| Operator code | web/src/core/metrics/quality.ts, qualityMetrics |
Overview¶
Quality metrics compare the active image with a reference image and report four numbers: PSNR, SSIM, MSE and MAE. Open them with Filter > Quality metrics, or in the Metrics panel. The reference is the original of the active image, or another open image of the same size. A common use is to add noise to a clean image, run a denoising filter, and measure how close the result is to the original.
How it works¶
- Choose the reference in the Metrics panel.
- The panel adds up the pixel differences for MSE and MAE, and computes PSNR from MSE.
- It computes local means, variances and covariance with a Gaussian window for SSIM.
- The numbers update when the image or the reference changes.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(I, R\): The image and the reference
- \(N\): The number of pixels
- \(\mu, \sigma\): Local means and standard deviations
- \(\sigma_{IR}\): The local covariance
I is the image and R the reference, over N pixels and three channels. MAE is the mean of the absolute differences. PSNR is infinite for equal images. In SSIM the means, variances and covariance are local, from a Gaussian window with sigma 1.5. C_1 = (0.01 x 255)^2 and C_2 = (0.03 x 255)^2 keep the ratio stable in flat areas. The SSIM map is averaged over the image without its 5-pixel frame, as in skimage.metrics.structural_similarity.
MSE and MAE are averages of the error. PSNR rescales MSE to decibels relative to the largest value, 255, so a higher PSNR means a smaller error. SSIM, from Wang, Bovik, Sheikh and Simoncelli, compares local brightness, contrast and structure. It ranges from -1 to 1, with 1 for equal images, and it agrees better with how people judge quality than MSE does.
Kernel or operator¶
SSIM uses a Gaussian window with sigma 1.5, truncated at 3.5 sigma, so it is 11 pixels wide. The other three metrics compare pixel by pixel.
Algorithm¶
- Choose the reference, the original of this image or another open image of the same size.
- Add up the squared and absolute differences for MSE and MAE, and compute PSNR from MSE.
- Blur the images, their squares and their product with a Gaussian of sigma 1.5.
- Compute the SSIM map from these local moments and average it inside the frame.
Implementation¶
qualityMetrics in web/src/core/metrics/quality.ts computes all four numbers. SSIM follows skimage.metrics.structural_similarity with Gaussian weights and the population covariance: the blur uses the reflect mode, and a 5-pixel frame is left out of the mean. The Metrics panel runs it in the main thread and keeps the result for each pair of images, so redrawing the panel costs nothing. The catalog entry names the command filter.metrics, which opens the panel.
Worked example¶
Take one pixel channel with value 120 in the image and 100 in the reference. Its squared difference is 400 and its absolute difference 20. If every channel of every pixel differs by 20, then MSE = 400, MAE = 20, and PSNR = 10 log10(65025 / 400) = 22.11 dB. An MSE of 4, a difference of 2 everywhere, gives 42.11 dB.
Complexity¶
- Time: \(O(N)\)
- Memory: \(O(N)\)
N is the number of pixels. SSIM needs five separable Gaussian blurs per channel.
Artifacts and limitations¶
Limitations
- All four need an aligned reference of the same size.
- None of them fully matches how people judge quality.
Artifacts
- None. The metrics do not change the image.
Tests¶
The fixture script computes the four metrics of a smooth image and a noisy copy with skimage.metrics: mean_squared_error, peak_signal_noise_ratio and structural_similarity with Gaussian weights. The test matches MSE, MAE and PSNR to 9 decimals and SSIM within 0.00001. Other tests check equal images and the size checks.
References¶
- Wang, Z., Bovik, A. C., Sheikh, H. R. and Simoncelli, E. P. Image quality assessment, from error visibility to structural similarity. IEEE Transactions on Image Processing 13(4), 600 to 612, 2004. DOI 10.1109/TIP.2003.819861.
- scikit-image documentation, skimage.metrics. https://scikit-image.org/docs/stable/api/skimage.metrics.html