Merge#
- class deeptrack.features.Merge(function: Callable[[...], Callable[[List[Image]], Image | List[Image]]], **kwargs: Dict[str, Any])#
Bases:
Feature
Apply a custom function to a list of images.
This feature allows the application of a user-defined function to a list of images. The function parameter must be a callable wrapped in an outer layer that can depend on other properties. The inner layer of the callable should process a list of images.
Note that 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 an image as input.
Parameters#
- functionCallable[…, Callable[[List[Image]], Image or List[Image]]]
A callable that produces a function. The outer function can depend on other properties of the pipeline, while the inner function takes a list of images and returns a single image or a list of images.
- **kwargsDict[str, Any]
Additional parameters passed to the parent Feature class.
Example#
>>> import numpy as np >>> from deeptrack.features import Merge, Image
Define a merge function that combines images by averaging:
>>> def merge_function_factory(): ... def merge_function(images): ... return np.mean(np.stack(images), axis=0) ... return merge_function
Create a Merge feature:
>>> merge_feature = Merge(function=merge_function_factory)
Apply the feature to a list of images:
>>> image_1 = Image(np.ones((5, 5)) * 2) >>> image_2 = Image(np.ones((5, 5)) * 4) >>> output_image = merge_feature([image_1, image_2]) >>> 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
(list_of_images, function, **kwargs)Apply the custom function to the list of images.
Methods Documentation
- get(list_of_images: List[Image], function: Callable[[List[Image]], Image | List[Image]], **kwargs: Dict[str, Any]) Image | List[Image] #
Apply the custom function to the list of images.
Parameters#
- list_of_imagesList[Image]
A list of images to be processed by the function.
- functionCallable[[List[Image]], Image or List[Image]]
The function to apply to the list of images.
- **kwargsDict[str, Any]
Additional arguments (unused here).
Returns#
- Image or List[Image]
The result of applying the function to the list of images.