Downsampling#
- class deepinv.physics.Downsampling(img_size=None, filter='warn', factor=2, device='cpu', padding='circular', **kwargs)[source]#
Bases:
LinearPhysicsDownsampling 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 customtorch.Tensorfilter. IfNone, no filtering is applied. Bicubic downsampling is a sensible default if you are not sure which filter to use.img_size (tuple[int], None) – optional size of the high resolution image
(C, H, W). Iftuple, use this fixed image size. IfNone, override on-the-fly using input data size andfactor(note that here,A_adjointwill only produce even img shapes).factor (int) – downsampling factor
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.device (torch.device, str) – Device this physics lives on. If filter is updated, it will be cast to Downsampling’s device.
- 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, list[str]) – 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
factoris passed,filtermust also be passed as astrorTensor, 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, list[str]) – 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
factoris passed,filtermust also be passed as astrorTensor, 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. Iftorch.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:
- 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, str, list[str]) – 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:#
Regularization by Denoising (RED) for Super-Resolution.