Blur

class deepinv.physics.Blur(filter=None, padding='valid', device='cpu', **kwargs)[source]

Bases: LinearPhysics

Blur operator.

This forward operator performs

\[y = w*x\]

where \(*\) denotes convolution and \(w\) is a filter.

Parameters:
  • filter (torch.Tensor) – Tensor of size (b, 1, h, w) or (b, c, h, w) in 2D; (b, 1, d, h, w) or (b, c, d, h, w) in 3D, containing the blur filter, e.g., deepinv.physics.blur.gaussian_filter().

  • padding (str) – options are 'valid', 'circular', 'replicate' and 'reflect'. If padding='valid' the blurred output is smaller than the image (no padding) otherwise the blurred output has the same size as the image. (default is 'valid'). Only padding='valid' and padding = 'circular' are implemented in 3D.

  • device (str) – cpu or cuda.

Note

This class makes it possible to change the filter at runtime by passing a new filter to the forward method, e.g., y = physics(x, w). The new filter \(w\) is stored as the current filter.

Note

This class uses the highly optimized torch.nn.functional.conv2d() for performing the convolutions in 2D and FFT for performing the convolutions in 3D as implemented in deepinv.physics.functional.conv3d_fft(). It uses FFT based convolutions in 3D since torch.functional.nn.conv3d() is slow for large kernels.


Examples:

Blur operator with a basic averaging filter applied to a 16x16 black image with a single white pixel in the center:

>>> from deepinv.physics import Blur
>>> x = torch.zeros((1, 1, 16, 16)) # Define black image of size 16x16
>>> x[:, :, 8, 8] = 1 # Define one white pixel in the middle
>>> w = torch.ones((1, 1, 2, 2)) / 4 # Basic 2x2 averaging filter
>>> physics = Blur(filter=w)
>>> y = physics(x)
>>> y[:, :, 7:10, 7:10] # Display the center of the blurred image
tensor([[[[0.2500, 0.2500, 0.0000],
          [0.2500, 0.2500, 0.0000],
          [0.0000, 0.0000, 0.0000]]]])
A(x, filter=None, **kwargs)[source]

Applies the filter to the input image.

Parameters:
  • x (torch.Tensor) – input image.

  • filter (torch.Tensor) – Filter \(w\) to be applied to the input image. If not None, it uses this filter instead of the one defined in the class, and the provided filter is stored as the current filter.

A_adjoint(y, filter=None, **kwargs)[source]

Adjoint operator of the blur operator.

Parameters:
  • y (torch.Tensor) – blurred image.

  • filter (torch.Tensor) – Filter \(w\) to be applied to the input image. If not None, it uses this filter instead of the one defined in the class, and the provided filter is stored as the current filter.

update_parameters(filter=None, **kwargs)[source]

Updates the current filter.

Parameters:

filter (torch.Tensor) – New filter to be applied to the input image.

Examples using Blur:

Imaging inverse problems with adversarial networks

Imaging inverse problems with adversarial networks

3D diffraction PSF

3D diffraction PSF

A tour of forward sensing operators

A tour of forward sensing operators

A tour of blur operators

A tour of blur operators