plenoptic.metric.mse#

plenoptic.metric.mse(img1, img2)[source]#

Return the MSE between img1 and img2.

Our baseline metric to compare two images is often mean-squared error, MSE. This is not a good approximation of the human visual system, but is handy to compare against.

For two images, \(x\) and \(y\), with \(n\) pixels each:

\[MSE = \frac{1}{n}\sum_i (x_i - y_i)^2\]
Parameters:
  • img1 (Tensor) – The first image to compare.

  • img2 (Tensor) – The second image to compare, must be same size as img1.

Return type:

Tensor

Returns:

mse – The mean-squared error between img1 and img2.

Raises:

RuntimeError – If img1 and img2 aren’t the same size.

Examples

>>> import plenoptic as po
>>> import torch
>>> einstein = po.data.einstein()
>>> po.set_seed(0)
>>> einstein_noisy = einstein + 0.1 * torch.randn_like(einstein)
>>> po.metric.mse(einstein, einstein_noisy)
tensor([[0.0100]])