Chain#

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

Bases: StructuralFeature

Resolve two features sequentially.

This feature resolves two features sequentially, passing the output of the first feature as the input to the second.

Parameters#

feature_1Feature

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

feature_2Feature

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

**kwargsDict[str, Any]

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

Example#

Let us create a feature chain where the first feature adds an offset to an image, and the second feature multiplies it by a constant.

>>> import numpy as np
>>> from deeptrack.features import Chain, Feature

Define the features:

>>> class Addition(Feature):
...     '''Simple feature that adds a constant.'''
...     def get(self, image, **kwargs):
...         # 'addend' property set via self.properties (default: 0).
...         return image + self.properties.get("addend", 0)()
>>> class Multiplication(Feature):
...     '''Simple feature that multiplies by a constant.'''
...     def get(self, image, **kwargs):
...         # 'multiplier' property set via self.properties (default: 1).
...         return image * self.properties.get("multiplier", 1)()

Chain the features:

>>> A = Addition(addend=10)
>>> M = Multiplication(multiplier=0.5)
>>> chain = A >> M  

Equivalent to:

>>> chain = Chain(A, M)

Create a dummy image:

>>> dummy_image = np.ones((60, 80))

Apply the chained features:

>>> transformed_image = chain(dummy_image)

In this example, the image is first passed through the Addition feature to add an offset, and then through the Multiplication feature to multiply by a constant factor.

Methods Summary

get(image[, _ID])

Apply the two features in sequence on the given input image(s).

Methods Documentation

get(image: Image | List[Image], _ID: Tuple[int, ...] = (), **kwargs: Dict[str, Any]) Image | List[Image]#

Apply the two features in sequence on the given input image(s).

Parameters#

imageImage or List[Image]

The input data (image or list of images) to transform.

_IDTuple[int, …], optional

A unique identifier for caching/parallel calls.

**kwargsDict[str, Any]

Additional parameters passed to or sampled by the features. Generally unused here, since each sub-feature will fetch what it needs from their own properties.

Returns#

Image or List[Image]

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