Chain#

class deeptrack.features.Chain(feature_1: Feature, feature_2: Feature, **kwargs: dict[str, Any])#

Bases: StructuralFeature

Resolve two features sequentially.

This feature applies two features sequentially, passing the output of the first feature as the input to the second. It enables building feature chains that execute complex transformations by combining simple operations.

Parameters#

feature_1: Feature

The first feature in the chain. Its output is passed to feature_2.

feature_2: Feature

The second feature in the chain, which processes the output from feature_1.

**kwargs: dict of str to Any, optional

Additional keyword arguments passed to the parent StructuralFeature (and, therefore, Feature).

Methods#

get(image: np.ndarray | list[np.ndarray] | Image | list[Image], _ID: tuple[int, …], **kwargs: dict[str, Any]) -> Image | list[Image]

Apply the two features in sequence on the given input image.

Notes#

This feature is used to combine simple operations into a pipeline without the need for explicit function chaining. It is syntactic sugar for creating sequential feature pipelines.

Examples#

>>> import deeptrack as dt
>>> import numpy as np

Create a feature chain where the first feature adds a constant offset, and the second feature multiplies the result by a constant:

>>> A = dt.Add(value=10)
>>> M = dt.Multiply(value=0.5)

Chain the features: >>> chain = A >> M

Equivalent to: >>> chain = dt.Chain(A, M)

Create a dummy image: >>> dummy_image = np.ones((2, 4))

Apply the chained features: >>> transformed_image = chain(dummy_image) >>> print(transformed_image) [[5.5 5.5 5.5 5.5] [5.5 5.5 5.5 5.5]]

Methods Summary

get(image[, _ID])

Apply the two features sequentially to the given input image(s).

Methods Documentation

get(image: np.ndarray | list[np.ndarray] | Image | list[Image], _ID: tuple[int, ...] = (), **kwargs: dict[str, Any]) Image | list[Image]#

Apply the two features sequentially to the given input image(s).

This method first applies feature_1 to the input image(s) and then passes the output through feature_2.

Parameters#

image: np.ndarray or list np.ndarray or Image or list of Image

The input data, which can be an Image or a list of Image objects, to transform sequentially.

_ID: tuple of int, optional

A unique identifier for caching or parallel execution. Defaults to an empty tuple.

**kwargs: dict of str to Any

Additional parameters passed to or sampled by the features. These are generally unused here, as each sub-feature fetches its required properties internally.

Returns#

Image or list of Images

The final output after feature_1 and then feature_2 have processed the input.