Downsampling#

class deepinv.physics.Downsampling(img_size=None, filter=None, factor=2, device='cpu', padding='circular', **kwargs)[source]#

Bases: LinearPhysics

Downsampling operator for super-resolution problems.

It is defined as

\[y = S (h*x)\]

where \(h\) is a low-pass filter and \(S\) is a subsampling operator.

Parameters:
  • filter (torch.Tensor, str, None) – Downsampling filter. It can be 'gaussian', 'bilinear', 'bicubic' , 'sinc' or a custom torch.Tensor filter. If None, no filtering is applied.

  • img_size (tuple[int], None) – optional size of the high resolution image (C, H, W). If tuple, use this fixed image size. If None, override on-the-fly using input data size and factor (note that here, A_adjoint will only produce even img shapes).

  • factor (int) – downsampling factor

  • 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.


Examples:

Downsampling operator with a gaussian filter:

>>> from deepinv.physics import Downsampling
>>> x = torch.zeros((1, 1, 32, 32)) # Define black image of size 32x32
>>> x[:, :, 16, 16] = 1 # Define one white pixel in the middle
>>> physics = Downsampling(filter = "gaussian", img_size=(1, 32, 32), factor=2)
>>> y = physics(x)
>>> y[:, :, 7:10, 7:10] # Display the center of the downsampled image
tensor([[[[0.0146, 0.0241, 0.0146],
          [0.0241, 0.0398, 0.0241],
          [0.0146, 0.0241, 0.0146]]]])
A(x, filter=None, factor=None, **kwargs)[source]#

Applies the downsampling operator to the input image.

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

  • filter (None, str, torch.Tensor) – Filter \(h\) to be applied to the input image before downsampling. If not None, it uses this filter and stores it as the current filter.

  • factor (int, float, torch.Tensor) – downsampling factor. If not None, use this factor and store it as current factor.

Warning

If factor is passed, filter must also be passed as a str or Tensor, in order to update the filter to the new factor.

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

Adjoint operator of the downsampling operator.

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

  • filter (None, str, torch.Tensor) – Filter \(h\) to be applied to the input image before downsampling. If not None, it uses this filter and stores it as the current filter.

  • factor (int, float, torch.Tensor) – downsampling factor. If not None, use this factor and store it as current factor.

Warning

If factor is passed, filter must also be passed as a str or Tensor, in order to update the filter to the new factor.

check_factor(factor)[source]#

Check new downsampling factor.

Parameters:

factor (int, float, torch.Tensor) – downsampling factor to be checked and cast to int. If torch.Tensor, it must be 1D and all its elements must be the same, since downsampling only supports one factor per batch.

Returns:

int: factor

Return type:

int

prox_l2(z, y, gamma, use_fft=True, **kwargs)[source]#

If the padding is circular, it computes the proximal operator with the closed-formula of Zhu et al.[1].

Otherwise, it computes it using the conjugate gradient algorithm which can be slow if applied many times.


References:

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

Updates the current filter and/or factor.

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

  • factor (int, float, torch.Tensor) – New downsampling factor to be applied to the input image.

Examples using Downsampling:#

A tour of forward sensing operators

A tour of forward sensing operators

Remote sensing with satellite images

Remote sensing with satellite images

Regularization by Denoising (RED) for Super-Resolution.

Regularization by Denoising (RED) for Super-Resolution.

Vanilla Unfolded algorithm for super-resolution

Vanilla Unfolded algorithm for super-resolution