Probability#
- class deeptrack.features.Probability(feature: Feature, probability: float | Callable[[...], float], *args: list[Any], **kwargs: dict[str, Any])#
Bases:
StructuralFeatureResolve a feature with a certain probability.
This feature conditionally applies a given feature to an input image based on a specified probability. A random number is sampled, and if it is less than probability, the feature is resolved; otherwise, the input image remains unchanged.
Parameters#
- feature: Feature
The feature to resolve conditionally.
- probability: PropertyLike[float]
The probability (between 0 and 1) of resolving the feature.
- *args: list[Any], optional
Positional arguments passed to the parent StructuralFeature class.
- **kwargs: dict of str to Any, optional
Additional keyword arguments passed to the parent StructuralFeature class.
Methods#
- get(image: np.ndarray, probability: float, random_number: float, **kwargs: dict[str, Any]) -> np.ndarray
Resolves the feature if the sampled random number is less than the specified probability.
Examples#
>>> import deeptrack as dt >>> import numpy as np
In this example, the Add feature is applied to the input image with a 70% chance. Define a feature and wrap it with Probability: >>> add_feature = dt.Add(value=2) >>> probabilistic_feature = dt.Probability(add_feature, probability=0.7)
Define an input image: >>> input_image = np.ones((5, 5))
Apply the feature: >>> output_image = probabilistic_feature(input_image)
Methods Summary
get(image, probability, random_number, **kwargs)Resolve the feature if a random number is less than the probability.
Methods Documentation
- get(image: ndarray, probability: float, random_number: float, **kwargs: dict[str, Any]) ndarray#
Resolve the feature if a random number is less than the probability.
Parameters#
- image: np.ndarray
The input image to process.
- probability: float
The probability (between 0 and 1) of resolving the feature.
- random_number: float
A random number sampled to determine whether to resolve the feature.
- **kwargs: dict of str to Any
Additional arguments passed to the feature’s resolve method.
Returns#
- np.ndarray
The processed image. If the feature is resolved, this is the output of the feature; otherwise, it is the unchanged input image.