Blur#
- class deepinv.physics.Blur(filter=None, padding='valid', use_fft=False, device=torch.device('cpu'), **kwargs)[source]#
Bases:
LinearPhysicsBlur 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_blur().padding (str) – options are
'valid','circular','replicate'and'reflect'. Ifpadding='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'). Onlypadding='valid'andpadding = 'circular'are implemented in 3D.use_fft (bool) – whether to use FFT-based convolutions. If
True, it uses FFT-based convolutions which can be faster for large kernels. IfFalse, it uses the standard convolution functions fromtorch.nn.functional.device (torch.device, str) – Device this physics lives on. If filter is updated, it will be cast to Blur’s device.
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 performs a true convolution, not a cross-correlation as the standard convolution functions in
torch.nn.functional. It is recommended to useuse_fft=Truefor large filters, anduse_fft=Falsefor small filters, since FFT-based convolutions can be faster for large kernels but slower for small 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.
- Raises:
ValueError – if the input tensor does not have 4 or 5 dimensions.
- 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.
- Raises:
ValueError – if the input tensor does not have 4 or 5 dimensions.
Examples using Blur:#
Imaging inverse problems with adversarial networks
Reducing the memory and computational complexity of unfolded network training