plenoptic.process.add_noise#

plenoptic.process.add_noise(img, noise_mse)[source]#

Add normally distributed noise to an image.

This adds normally-distributed noise to an image so that the resulting noisy version has the specified mean-squared error.

Parameters:
  • img (Tensor) – The image to make noisy.

  • noise_mse (float | list[float]) – The target MSE value / variance of the noise. More than one value is allowed.

Return type:

Tensor

Returns:

noisy_img – The noisy image. If noise_mse contains only one element, this will be the same size as img. Else, each separate value from noise_mse will be along the batch dimension.

Examples

Basic usage:

>>> import plenoptic as po
>>> import torch
>>> img = po.data.einstein()
>>> img.shape
torch.Size([1, 1, 256, 256])
>>> noisy = po.process.add_noise(img, noise_mse=0.1)
>>> noisy.shape
torch.Size([1, 1, 256, 256])
>>> po.plot.imshow([img, noisy])
<PyrFigure ...>

(png, hires.png, pdf)

../../_images/plenoptic-process-add_noise-1.png

With multiple elements in noise_mse:

>>> noisy_multi = po.process.add_noise(img, noise_mse=[0.01, 0.1, 1.0])
>>> noisy_multi.shape
torch.Size([3, 1, 256, 256])
>>> po.plot.imshow([img, noisy_multi])
<PyrFigure ...>

(png, hires.png, pdf)

../../_images/plenoptic-process-add_noise-2.png