deeptrack.optical.math Module#
Mathematical operations and structures.
This module provides classes and utilities to perform common mathematical operations on images, including clipping, normalization, blurring, pooling, resizing, and morphology. All operations are implemented as subclasses of Feature, enabling seamless integration with the feature-based design of the library.
Key Features#
Clipping
Restrict image values to a specified range.
Normalization
Adjust image values to a common scale.
Blurring
Smooth images using various filters.
Pooling
Downsample images by applying a function to local regions.
Resizing
Change the dimensions of images.
Morphology
Binary dilation and erosion on masks.
Module Structure#
Helper functions:
- _prepare_mask: Normalize mask shape and channel handling for morphological
operations.
isotropic_dilation: Apply isotropic dilation to a binary mask.
isotropic_erosion:Apply isotropic erosion to a binary mask.
move_channel_last: Move the channel axis to the last position.
restore_channel_axis:Restore the channel axis to its original position.
pad_image_to_fft: Pad an image to optimal size for FFT-based operations.
Classes:
Average: Compute the mean across a list of inputs.
Clip: Clip values to a specified minimum and maximum.
NormalizeMinMax: Perform min–max normalization.
NormalizeStandard: Normalize to zero mean and unit variance.
NormalizeQuantile: Normalize based on specified quantiles.
Blur: Base class for blurring operations.
AverageBlur: Apply mean filtering.
GaussianBlur: Apply Gaussian filtering.
MedianBlur: Apply median filtering.
Pool: Base class for pooling operations.
AveragePooling: Apply average pooling.
MaxPooling: Apply max pooling.
MinPooling: Apply min pooling.
SumPooling: Apply sum pooling.
MedianPooling: Apply median pooling.
Resize: Resize images to a specified spatial size.
BlurCV2: Apply OpenCV-based blurring (NumPy backend only).
BilateralBlur: Apply bilateral filtering for edge-preserving smoothing.
Examples#
>>> import deeptrack as dt
Define a simple pipeline with mathematical operations.
Create features for clipping and normalization.
>>> clip = dt.Clip(min=0, max=200)
>>> normalize = dt.NormalizeMinMax()
Chain features together.
>>> pipeline = clip >> normalize
Process an input image.
>>> import numpy as np
>>>
>>> input_image = np.array([0, 100, 200, 400])
>>> output_image = pipeline(input_image)
>>> print(output_image)
[0., 0.5, 1., 1.]
Functions#
|
Apply binary dilation to a mask. |
|
Apply binary erosion to a mask. |
|
Pad an image to improve Fast Fourier Transform (FFT) performance. |
Classes#
|
Average of input arrays. |
|
Clip values of an array to a specified range. |
|
Min-max normalization of an array. |
|
Standardize an array to zero mean and unit variance. |
|
Quantile-based normalization. |
|
Backend-dispatched abstract base class for blurring operations. |
|
Blur an image by computing simple means over neighbourhoods. |
|
Apply a Gaussian blur over spatial dimensions. |
|
Apply a median filter over spatial dimensions. |
|
Abstract base class for pooling operations. |
|
Average pooling over spatial dimensions. |
|
Max pooling over spatial dimensions. |
|
Min pooling over spatial dimensions. |
|
Sum pooling over spatial dimensions. |
|
Median pooling over spatial dimensions. |
|
Resize an image to a specified spatial size. |
|
Apply a blurring filter using OpenCV (cv2). |
|
Apply bilateral filtering using OpenCV (cv2.bilateralFilter). |