Slice#
- class deeptrack.features.Slice(slices: Iterable[int | Callable[[...], int]] | Callable[[...], Iterable[int | Callable[[...], int]]], **kwargs: Dict[str, Any])#
Bases:
Feature
Array indexing for each Image in list.
This feature applies slicing to the input image(s) based on the specified slices. While this feature can be used directly, it is generally easier to apply normal array indexing on a feature directly.
Parameters#
- slicesIterable of int, slice, or ellipsis
The slicing instructions for each dimension, specified as an iterable of integers, slices, or ellipses. Each element corresponds to a dimension in the input image.
- **kwargsdict
Additional keyword arguments passed to the parent Feature class.
Examples#
Note, this feature is rarely needed to be used directly. Instead, you can do normal array indexing on a feature directly.
For example, using lambda to demonstrate different ways to interact with the slices. In this case, the lambda keyword is redundant.
>>> feature = dt.DummyFeature() >>> sliced_feature = feature[ ... lambda: 0 : lambda: 1, # Slices the first dimension. ... 1:2, # Slices the second dimension. ... lambda: slice(None, None, -2) # Steps through the third dimension. ... ] >>> sliced_feature.resolve(np.arange(27).reshape((3, 3, 3)))
Using Slice directly can be required in some cases, however. For example if dependencies between properties are required. In this case, one can replicate the previous example as follows:
>>> feature = dt.DummyFeature() >>> sliced_feature = feature + dt.Slice(
… slices=lambda dim1, dim2: (dim1, dim2), … dim1=slice(lambda: 0, lambda: 1, 1), … dim2=slice(1, 2, None), … dim3=lambda: slice(None, None, -2) … ) >>> sliced_feature.resolve(np.arange(27).reshape((3, 3, 3)))
In both examples, slices can depend on other properties or be defined dynamically.
Methods Summary
get
(image, slices, **kwargs)Apply the specified slices to the input image.
Methods Documentation
- get(image: ndarray, slices: Tuple[Any, ...] | Any, **kwargs: Dict[str, Any])#
Apply the specified slices to the input image.
Parameters#
- imagenp.ndarray
The input image to be sliced.
- slicesUnion[Tuple[Any, …], Any]
The slicing instructions for the input image.
- **kwargsdict
Additional keyword arguments (unused in this implementation).
Returns#
- np.ndarray
The sliced image.