plenoptic.process.LaplacianPyramid#
Note
This object is a torch.nn.Module. It therefore has all the methods and attributes
from that class, even though they are not documented here (to avoid cluttering this page).
- class plenoptic.process.LaplacianPyramid(n_scales=5, scale_filter=False)[source]#
Bases:
ModuleLaplacian Pyramid in Torch.
The Laplacian pyramid (Burt and Adelson, 1983, [1]) is a multiscale image representation. It decomposes the image by computing the local mean using Gaussian blurring filters and subtracting it from the image and repeating this operation on the local mean itself after downsampling. This representation is overcomplete and invertible.
- Parameters:
n_scales (
int(default:5)) – Number of scales to compute.scale_filter (
bool(default:False)) – IfTrue, the norm of the downsampling/upsampling filter is 1. IfFalse, it is 2. If the norm is 1, the image is multiplied by 4 during the upsampling operation; the net effect is that the \(n\) -th scale of the pyramid is divided by \(2^n\).
References
Examples
>>> import plenoptic as po >>> lpyr = po.process.LaplacianPyramid(n_scales=4, scale_filter=True)
Methods
forward(x)Build the Laplacian pyramid of an image.
recon_pyr(y)Reconstruct the image from its Laplacian pyramid coefficients.
- forward(x)[source]#
Build the Laplacian pyramid of an image.
Builds a Laplacian pyramid of height
self.n_scales. Because the tensor at each scale will have a different height and width, we return a list of tensors instead of a single tensor.- Parameters:
x (
Tensor) – Image, or batch of images of shape (batch, channel, height, width). If there are multiple batches or channels, the Laplacian is computed separately for each of them.- Return type:
- Returns:
y – Laplacian pyramid representation, each element of the list corresponds to a scale, from fine to coarse.
Examples
>>> import plenoptic as po >>> img = po.data.einstein() >>> lpyr = po.process.LaplacianPyramid() >>> po.plot.imshow(lpyr(img)) <PyrFigure ...>
- recon_pyr(y)[source]#
Reconstruct the image from its Laplacian pyramid coefficients.
The input to
recon_pyrshould be list of tensors similar to those returned byself.forward.- Parameters:
y (
list[Tensor]) – Laplacian pyramid representation, each element of the list corresponds to a scale, from fine to coarse.len(y)should beself.n_scales.- Return type:
- Returns:
x – Image, or batch of images.
Examples
>>> import plenoptic as po >>> import torch >>> img = po.data.einstein() >>> lpyr = po.process.LaplacianPyramid() >>> coeffs = lpyr(img) >>> recon = lpyr.recon_pyr(coeffs) >>> torch.allclose(img, recon) True >>> titles = ["Original", "Reconstructed", "Difference"] >>> po.plot.imshow([img, recon, img - recon], title=titles) <PyrFigure ...>