Lambda#
- class deeptrack.features.Lambda(function: Callable[[...], Callable[[Image], Image]], **kwargs: Dict[str, Any])#
Bases:
Feature
Apply a custom function on each image in the input.
This feature allows applying a user-defined function to individual imagen in the input pipeline. The property function needs to be wrapped in an outer layer function. The outer layer function can depend on other properties, while the inner layer function accepts only an image as input.
Parameters#
- functionCallable[…, Callable[[Image], Image]]
Function that takes the current image as first input. A callable that produces a function. The outer function can depend on other properties of the pipeline, while the inner function processes a single image.
- **kwargsDict[str, Any]
Additional parameters passed to the parent Feature class.
Example#
>>> import numpy as np >>> from deeptrack.features import Lambda, Image
Define a lambda function that scales an image:
>>> def scale_function_factory(scale=2): ... def scale_function(image): ... return image * scale ... return scale_function
Create a Lambda feature:
>>> lambda_feature = Lambda(function=scale_function_factory(scale=3))
Apply the feature to an image:
>>> input_image = Image(np.ones((5, 5))) >>> output_image = lambda_feature(input_image) >>> print(output_image) [[3. 3. 3. 3. 3.] [3. 3. 3. 3. 3.] [3. 3. 3. 3. 3.] [3. 3. 3. 3. 3.] [3. 3. 3. 3. 3.]]
Methods Summary
get
(image, function, **kwargs)Apply the custom function to the image.
Methods Documentation
- get(image: Image, function: Callable[[Image], Image], **kwargs: Dict[str, Any])#
Apply the custom function to the image.
Parameters#
- imageImage
The input image to be processed by the function.
- functionCallable[[Image], Image]
The function to apply to the image.
- **kwargsDict[str, Any]
Additional arguments (unused here).
Returns#
- Image
The result of applying the function to the image.