Lambda#

class deeptrack.features.Lambda(function: Callable[[...], Callable[[Image], Image]], **kwargs: dict[str, Any])#

Bases: Feature

Apply a user-defined function to each image in the input.

This feature allows applying a custom function to individual images in the input pipeline. The function parameter must be wrapped in an outer function that can depend on other properties of the pipeline. The inner function processes a single image.

Parameters#

function: Callable[…, Callable[[Image], Image]]

A callable that produces a function. The outer function can accept additional arguments from the pipeline, while the inner function operates on a single image.

**kwargs: dict[str, Any]

Additional keyword arguments passed to the parent Feature class.

Methods#

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

Applies the custom function to the input image.

Examples#

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

Define a factory function that returns a scaling function: >>> def scale_function_factory(scale=2): … def scale_function(image): … return image * scale … return scale_function

Create a Lambda feature that scales images by a factor of 5: >>> lambda_feature = dt.Lambda(function=scale_function_factory, scale=5)

Apply the feature to an image: >>> input_image = np.ones((5, 5)) >>> output_image = lambda_feature(input_image) >>> print(output_image) [[5. 5. 5. 5. 5.]

[5. 5. 5. 5. 5.] [5. 5. 5. 5. 5.] [5. 5. 5. 5. 5.] [5. 5. 5. 5. 5.]]

Methods Summary

get(image, function, **kwargs)

Apply the custom function to the input image.

Methods Documentation

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

Apply the custom function to the input image.

This method applies a user-defined function to transform the input image. The function should be a callable that takes an image as input and returns a modified version of it.

Parameters#

image: np.ndarray or Image

The input image to be processed.

function: Callable[[Image], Image]

A callable function that takes an image and returns a transformed image.

**kwargs: dict of str to Any

Additional keyword arguments (unused in this implementation).

Returns#

Image

The transformed image after applying the function.