Pad#
- class deeptrack.optical.augmentations.Pad(px: int | tuple[int, ...] | list[int] | Callable[[...], int | tuple[int, ...] | list[int]] = (0, 0, 0, 0), mode: str | Callable[[...], str] = 'constant', cval: float | Callable[[...], float] = 0, **kwargs: Any)#
Bases:
AugmentationPad an image by adding extra pixels along specified axes.
This augmentation adds padding to an image using functionality similar to numpy.pad. The padding is specified using a flat sequence px describing the number of pixels added before and after each axis.
Parameters#
- px: PropertyLike[int | tuple[int, …] | list[int]]
- Amount of padding for each axis, specified as a flat sequence
(before_axis0, after_axis0, before_axis1, after_axis1, …)
If a single integer is provided, the same padding is applied before and after every axis.
- mode: PropertyLike[str], optional
Padding mode used when extending the array. Supported modes follow numpy.pad and torch.nn.functional.pad. Defaults to “constant”.
- cval: PropertyLike[float], optional
Constant value used when mode=”constant”. Defaults to 0.
Methods#
- _get_numpy(image, **kwargs) -> np.ndarray
Apply padding to a NumPy array.
- _get_torch(image, **kwargs) -> torch.Tensor
Apply padding to a PyTorch tensor.
Returns#
- np.ndarray or torch.Tensor
The padded image.
Examples#
>>> import deeptrack as dt >>> particle = dt.PointParticle(position=(32, 32)) >>> optics = dt.Fluorescence() >>> pad = dt.Pad(px=(10, 10, 5, 5), mode="constant", cval=0) >>> image = optics(particle) >> pad >>> print(image.resolve().shape)