pad_image_to_fft#
- deeptrack.optical.math.pad_image_to_fft(image: ndarray | Tensor, axes: Iterable[int] = (0, 1)) ndarray | Tensor#
Pad an image to improve Fast Fourier Transform (FFT) performance. Padding is applied at the end of each axis (no centering).
Preserves backend: - NumPy input → NumPy output - Torch input → Torch output (preserves autograd compatibility)
This function pads an image by adding zeros to the end of specified axes so that their lengths match the nearest larger size in _FASTEST_SIZES. Sizes are chosen as products of small prime factors, which are efficient for FFT algorithms.
Parameters#
- image: np.ndarray | torch.Tensor
The input image to pad.
- axesiterable of int, optional
Axes along which to apply padding. Negative axes are supported.
Returns#
- np.ndarray | torch.Tensor
The padded image with dimensions optimized for FFT performance.
Raises#
- ValueError
If no suitable size is found in _FASTEST_SIZES for any axis length.
Examples#
>>> import numpy as np >>> from deeptrack.image import pad_image_to_fft
Pad a NumPy array:
>>> img = np.zeros((5, 11)) >>> padded_img = pad_image_to_fft(img) >>> print(padded_img.shape) (6, 12)