Slice#

class deeptrack.features.Slice(slices: PropertyLike[Iterable[int | slice | Ellipsis]], **kwargs: Any)#

Bases: Feature

Dynamically apply array indexing to inputs.

This feature allows dynamic slicing of an inoput 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: tuple[int | slice | ellipsis] | list[int | slice | ellipsis]

The slicing instructions for each dimension. Each element corresponds to a dimension in the input image.

**kwargs: Any

Additional keyword arguments passed to the parent Feature class.

Methods#

get(inputs, slices, _ID, **kwargs) -> array

Applies the specified slices to the input.

Examples#

>>> import deeptrack as dt

Recommended approach: Use normal indexing for static slicing:

>>> import numpy as np
>>>
>>> feature = dt.DummyFeature()
>>> static_slicing = feature[0:2, ::2, :]
>>> result = static_slicing.resolve(np.arange(27).reshape((3, 3, 3)))
>>> result
array([[[ 0,  1,  2],
        [ 6,  7,  8]],
       [[ 9, 10, 11],
        [15, 16, 17]]])

Using Slice for dynamic slicing (necessary when slices depend on computed properties):

>>> feature = dt.DummyFeature()
>>> dynamic_slicing = feature >> dt.Slice(
...     slices=(slice(0, 2), slice(None, None, 2), slice(None))
... )
>>> result = dynamic_slicing.resolve(np.arange(27).reshape((3, 3, 3)))
>>> result
array([[[ 0,  1,  2],
        [ 6,  7,  8]],
       [[ 9, 10, 11],
        [15, 16, 17]]])

In both cases, slices can be defined dynamically based on feature properties.

Methods Summary

get(array, slices, **kwargs)

Apply the specified slices to the input array.

Methods Documentation

get(array: ArrayLike[Any], slices: slice | tuple[int | slice | Ellipsis, ...], **kwargs: Any) ArrayLike[Any]#

Apply the specified slices to the input array.

Parameters#

array: array

The input array to be sliced.

slices: slice ellipsis or tuple[int or slice or ellipsis, …]

The slicing instructions for the input image. Typically it is a tuple. 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: Any

Additional keyword arguments (unused in this implementation).

Returns#

array or list[array]

The sliced array(s).