GaussianBlur#
- class deeptrack.optical.math.GaussianBlur(sigma: float | Callable[[...], float] = 2, channel_axis: int | None = -1, **kwargs: Any)#
Bases:
BlurApply a Gaussian blur over spatial dimensions.
The image is convolved with a Gaussian kernel with standard deviation sigma. If channel_axis is specified, the blur is applied independently per channel. Otherwise, all dimensions (including channels, if present) are treated as spatial, and the filter is applied across them. The implementation uses separable convolution for efficiency. For large sigma relative to the image size, the output approaches
the global mean of the image.
Parameters#
- sigma: float
Standard deviation of the Gaussian kernel.
- channel_axis: int or None, default=-1
Axis corresponding to channels. Set to None to treat all dimensions as spatial.
Methods#
- get(image, sigma, channel_axis, **kwargs) –> array | tensor
Apply Gaussian blurring to the input image using the selected backend.
Examples#
>>> import deeptrack as dt
Create an input image:
>>> import numpy as np >>> >>> input_image = np.random.rand(32, 32)
Define a Gaussian blur feature.
>>> gaussian_blur = dt.GaussianBlur(sigma=2, channel_axis=None) >>> output_image = gaussian_blur(input_image) >>> print(output_image.shape) (32, 32)
Visualize the input and output images.
>>> import matplotlib.pyplot as plt >>> >>> plt.figure(figsize=(8, 4)) >>> plt.subplot(1, 2, 1) >>> plt.imshow(input_image, cmap='gray') >>> plt.subplot(1, 2, 2) >>> plt.imshow(output_image, cmap='gray') >>> plt.show()