Slice#
- class deeptrack.features.Slice(slices: PropertyLike[Iterable[PropertyLike[int] | PropertyLike[slice] | PropertyLike[...]]], **kwargs: dict[str, Any])#
Bases:
FeatureDynamically applies array indexing to input Image(s).
This feature allows dynamic slicing of an image using integer indices, slice objects, or ellipses (…). While normal array indexing is preferred for static cases, Slice is useful when the slicing parameters must be computed dynamically based on other properties.
Parameters#
- slices: Iterable[int | slice | …]
The slicing instructions for each dimension. Each element corresponds to a dimension in the input image.
- **kwargs: dict of str to Any
Additional keyword arguments passed to the parent Feature class.
Methods#
- get(image: np.ndarray, slices: tuple[int | slice | …], **kwargs: dict[str, Any]) -> np.ndarray
Applies the specified slices to the input image.
Examples#
>>> import deeptrack as dt >>> import numpy as np
Recommended Approach: Use Normal Indexing for Static Slicing >>> feature = dt.DummyFeature() >>> static_slicing = feature[:, 1:2, ::-2] >>> result = static_slicing.resolve(np.arange(27).reshape((3, 3, 3))) >>> print(result)
Using `Slice` for Dynamic Slicing (when necessary) If slices depend on computed properties, use Slice: >>> feature = dt.DummyFeature() >>> dynamic_slicing = feature >> dt.Slice( … slices=(slice(None), slice(1, 2), slice(None, None, -2)) … ) >>> result = dynamic_slicing.resolve(np.arange(27).reshape((3, 3, 3))) >>> print(result)
In both cases, slices can be defined dynamically based on feature properties.
Methods Summary
get(image, slices, **kwargs)Apply the specified slices to the input image.
Methods Documentation
- get(image: np.ndarray, slices: tuple[Any, ...] | Any, **kwargs: dict[str, Any])#
Apply the specified slices to the input image.
Parameters#
- image: np.ndarray
The input image to be sliced.
- slices: tuple[int | slice | ellipsis, …] | int | slice | ellipsis
The slicing instructions for the input image. Each element in the tuple corresponds to a dimension in the input image. If a single element is provided, it is converted to a tuple.
- **kwargs: dict of str to Any
Additional keyword arguments (unused in this implementation).
Returns#
- np.ndarray
The sliced image.