ConditionalSetFeature#

class deeptrack.features.ConditionalSetFeature(on_false: Feature | None = None, on_true: Feature | None = None, condition: str | bool | Callable[[...], str | bool] = 'is_label', **kwargs: Dict[str, Any])#

Bases: StructuralFeature

Conditionally resolves one of two features based on a condition.

This feature allows dynamically selecting and resolving one of two child features depending on whether a specified condition evaluates to True or False.

The condition parameter specifies the name of the property to listen to. For example, if the condition is “is_label”, the selected feature can be toggled by calling:

>>> feature.resolve(is_label=True)  # Resolves on_true feature.
>>> feature.resolve(is_label=False)  # Resolves on_false feature.
>>> feature.update(is_label=True)  # Updates both features.

Both on_true and on_false features are updated in either case, even if only one of them is resolved.

Parameters#

on_falseFeature, optional

The feature to resolve if the conditional property evaluates to False. If not provided, the input image remains unchanged in this case.

on_trueFeature, optional

The feature to resolve if the conditional property evaluates to True. If not provided, the input image remains unchanged in this case.

conditionstr or bool, optional

The name of the conditional property, or a boolean value. Defaults to “is_label”.

**kwargsDict[str, Any]

Additional keyword arguments passed to the parent StructuralFeature.

Example#

>>> import deeptrack as dt
>>> true_feature = dt.GaussianNoise(sigma=5)
>>> false_feature = dt.GaussianNoise(sigma=0)
>>> conditional_feature = ConditionalSetFeature(
...     on_true=true_feature, 
...     on_false=false_feature, 
...     condition="is_label"
... )
>>> # Resolve based on the condition.
>>> image_with_noise = conditional_feature.resolve(is_label=False)
>>> image_without_noise = conditional_feature.resolve(is_label=True)

Methods Summary

get(image, *, condition, **kwargs)

Resolve the appropriate feature based on the condition.

Methods Documentation

get(image: Any, *, condition: str | bool, **kwargs: Dict[str, Any])#

Resolve the appropriate feature based on the condition.

Parameters#

imageAny

The input image to process.

conditionstr or bool

The name of the conditional property or a boolean value. If a string is provided, it is looked up in kwargs to get the actual boolean value.

**kwargsDict[str, Any]

Additional keyword arguments to pass to the resolved feature.

Returns#

Any

The processed image after resolving the appropriate feature. If neither on_true nor on_false is provided for the corresponding condition, the input image is returned unchanged.