isotropic_erosion#
- deeptrack.optical.math.isotropic_erosion(mask: ndarray | Tensor, radius: float, *, backend: str = 'numpy', device: device | None = None, dtype: dtype | None = None, channel_axis: int | None = None) ndarray | Tensor#
Apply binary erosion to a mask.
Performs morphological erosion using a structuring element of radius radius. Output is always boolean. Shape is preserved.
- If channel_axis is None:
(H, W) → treated as a 2D mask
(H, W, Z) → treated as a 3D volume
- If channel_axis is specified:
Operation is applied independently for each channel
- Singleton channel:
(H, W, 1) is treated as 2D and restored after processing
NumPy backend Uses skimage.morphology.isotropic_erosion, based on Euclidean distance.
Torch backend Uses convolution with a full kernel (square/cubic neighborhood), corresponding to Chebyshev distance. This is not strictly isotropic.
Parameters#
- masknp.ndarray or torch.Tensor
Input mask. Non-zero values are treated as foreground (mask > 0).
- radiusfloat
Radius of the structuring element. If radius <= 0, the input is returned unchanged.
- backend{“numpy”, “torch”}, default=”numpy”
Backend used for computation.
- devicetorch.device, optional
Device used for torch backend.
- dtypetorch.dtype, optional
Data type for torch computations.
- channel_axisint or None, optional
Axis corresponding to channels.
Returns#
- np.ndarray or torch.Tensor
Eroded mask (boolean) with the same shape as the input.