Probability#
- class deeptrack.features.Probability(feature: Feature, probability: float | Callable[[...], float], *args: List[Any], **kwargs: Dict[str, any])#
Bases:
StructuralFeature
Resolve 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 the probability, the feature is resolved; otherwise, the input image remains unchanged.
Parameters#
- featureFeature
The feature to resolve conditionally.
- probabilityfloat
The probability (between 0 and 1) of resolving the feature. A value of 0 ensures the feature is never resolved, while a value of 1 ensures it is always resolved.
- *argsList[Any], optional
Positional arguments passed to the parent StructuralFeature class.
- **kwargsDict[str, Any], optional
Additional keyword arguments passed to the parent StructuralFeature class.
Methods#
- get(image, feature, probability, random_number, **kwargs)
Resolves the feature if the sampled random number is less than the specified probability.
Example#
In this example, the GaussianBlur is applied to the input image with a 50% chance.
>>> import numpy as np >>> from deeptrack.features import Probability, GaussianBlur
Define a feature and wrap it with Probability:
>>> blur_feature = GaussianBlur(sigma=2) >>> probabilistic_feature = Probability(blur_feature, probability=0.5)
Define an input image:
>>> input_image = np.ones((10, 10))
Apply the feature:
>>> output_image = probabilistic_feature(input_image)
Methods Summary
get
(image, feature, probability, ...)Resolve the feature if a random number is less than the probability.
Methods Documentation
- get(image: ndarray, feature: Feature, probability: float, random_number: float, **kwargs)#
Resolve the feature if a random number is less than the probability.
Parameters#
- imagenp.ndarray
The input image to process.
- featureFeature
The feature to resolve conditionally.
- probabilityfloat
The probability (between 0 and 1) of resolving the feature.
- random_numberfloat
A random number sampled to determine whether to resolve the feature.
- **kwargsDict[str, 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.