Merge#

class deeptrack.features.Merge(function: Callable[..., Callable[[list[np.ndarray] | list[Image]], np.ndarray | list[np.ndarray] | Image | list[Image]]], **kwargs: dict[str, Any])#

Bases: Feature

Apply a custom function to a list of images.

This feature allows applying a user-defined function to a list of images. The function parameter must be a callable that returns another function, where:

  • The outer function can depend on other properties in the pipeline.

  • The inner function takes a list of images and returns a single

image or a list of images.

Note: The function must be wrapped in an outer layer to enable dependencies on other properties while ensuring correct execution.

Parameters#

function: Callable[…, Callable[[list[np.ndarray] | list[Image]], np.ndarray | list[np.ndarray] | Image | list[Image]]]

A callable that produces a function. The outer function can depend on other properties of the pipeline, while the inner function processes a list of images and returns either a single image or a list of images.

**kwargs: dict[str, Any]

Additional parameters passed to the parent Feature class.

Attributes#

__distributed__: bool

Indicates whether this feature distributes computation across inputs.

Methods#

get(list_of_images: list[np.ndarray] | list[Image], function: Callable[[list[np.ndarray] | list[Image]], np.ndarray | list[np.ndarray] | Image | list[Image]], **kwargs: dict[str, Any]) -> Image | list[Image]

Applies the custom function to the list of images.

Examples#

>>> import deeptrack as dt
>>> import numpy as np

Define a merge function that averages multiple images: >>> 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 = dt.Merge(function=merge_function_factory)

Apply the feature to a list of images: >>> image_1 = np.ones((5, 5)) * 2 >>> image_2 = 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 a list of images.

Methods Documentation

get(list_of_images: list[np.ndarray] | list[Image], function: Callable[[list[np.ndarray] | list[Image]], np.ndarray | list[np.ndarray] | Image | list[Image]], **kwargs: dict[str, Any]) Image | list[Image]#

Apply the custom function to a list of images.

Parameters#

list_of_images: list[np.ndarray] or list[Image]

A list of images to be processed by the function.

function: Callable[[list[np.ndarray] | list[Image]], np.ndarray | list[np.ndarray] | Image | list[Image]]
The function that processes the list of images and returns either:
  • A single transformed image (Image)

  • A list of transformed images (list[Image])

**kwargs: dict[str, Any]

Additional arguments (unused in this implementation).

Returns#

Image | list[Image]

The processed image(s) after applying the function.