torchimage.filtering package¶
Submodules¶
torchimage.filtering.generic module¶
Module contents¶
- class torchimage.filtering.EdgeFilter(edge_kernel, smooth_kernel, *, normalize=False, same_padder=None)¶
Bases:
torch.nn.modules.module.Module
- all_components(x, axes=None)¶
- component(x, edge_axis, smooth_axes)¶
- horizontal(x)¶
- magnitude(x, axes=None, *, epsilon=0.0, p=2)¶
- training: bool¶
- vertical(x)¶
- class torchimage.filtering.Farid(*, normalize=False, same_padder='reflect')¶
Bases:
torchimage.filtering.edges.EdgeFilter
- training: bool¶
- class torchimage.filtering.GaussianGrad(kernel_size, sigma, edge_kernel_size=None, edge_sigma=None, normalize=True, edge_order=1, same_padder='reflect')¶
Bases:
torchimage.filtering.edges.EdgeFilter
- training: bool¶
- class torchimage.filtering.Laplace(*, same_padder='reflect')¶
Bases:
torch.nn.modules.module.Module
Edge detection with discrete Laplace operator
Unlike SeparablePoolNd, which sequentially applies 1d convolution on previous output at each axis, Laplace simultaneously applies the kernel to each axis, generating n output tensors in parallel; these output tensors are then added to obtain a final output. Therefore, the equivalent kernel of SeparablePoolNd is the outer product of each 1d kernel; the equivalent kernel of LaplacePoolNd is the sum of 1d kernels (after they are expanded to the total number of dimensions).
For instance, 1d Laplace is [1, -2, 1] and 2d Laplace is [[0, 1, 0],
[1, -4, 1], [0, 1, 0]]
This method is less general than scipy’s generic_laplace, because we cannot customize a non-separable second derivative function.
This requires every 1d pooling to return a tensor of exactly the same shape, so we recommend
same=True
.- forward(x: torch.Tensor, axes)¶
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool¶
- class torchimage.filtering.LaplacianOfGaussian(kernel_size, sigma, *, same_padder='reflect')¶
Bases:
torch.nn.modules.module.Module
The same as scipy.ndimage.gaussian_laplace
- forward(x: torch.Tensor, axes=None)¶
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool¶
- class torchimage.filtering.Prewitt(*, normalize=False, same_padder='reflect')¶
Bases:
torchimage.filtering.edges.EdgeFilter
- training: bool¶
- class torchimage.filtering.Scharr(*, normalize=False, same_padder='reflect')¶
Bases:
torchimage.filtering.edges.EdgeFilter
- training: bool¶
- class torchimage.filtering.Sobel(*, normalize=False, same_padder='reflect')¶
Bases:
torchimage.filtering.edges.EdgeFilter
- training: bool¶
- class torchimage.filtering.UnsharpMask(blur: torchimage.pooling.base.BasePoolNd, amount=0.5, threshold=0, *, padder: Optional[torchimage.padding.generic_pad.Padder] = None)¶
Bases:
object
Sharpen an image with unsharp masking.
The basic formula of unsharp masking is: y = x + amount * (x - blur(x))
- blur¶
Smoothing (blurring) filter for unsharp masking.
A filter should output a tensor whose shape is completely the same as the input tensor. The to_filter method from base pooling will be automatically called here, so the user only needs to specify essential parameters, such as
GaussianPoolNd(kernel_size=7, sigma=1.5)
orAvgPoolNd(kernel_size=5)
- Type
- amountfloat
The “amount” of sharpening applied to the image.
See the formula for unsharp masking for more detailed explanation.
- thresholdfloat
Ignore differences between x and blur(x) that are below threshold. Default:
0.0
- forward(x: torch.Tensor, axes=slice(2, None, None))¶