Arguments#

class deeptrack.features.Arguments(_input: Any = [], **kwargs: dict[str, Any])#

Bases: Feature

A convenience container for pipeline arguments.

The Arguments feature allows dynamic control of pipeline behavior by providing a container for arguments that can be modified or overridden at runtime. This is particularly useful when working with parameterized pipelines, such as toggling behaviors based on whether an image is a label or a raw input.

Methods#

get(image: Any, **kwargs: dict[str, Any]) -> Any

Passes the input image through unchanged, while allowing for property overrides.

Examples#

>>> import deeptrack as dt
>>> from tempfile import NamedTemporaryFile
>>> from PIL import Image as PIL_Image
>>> import os

Create a temporary image: >>> test_image_array = (np.ones((50, 50)) * 128).astype(np.uint8) >>> temp_png = NamedTemporaryFile(suffix=”.png”, delete=False) >>> PIL_Image.fromarray(test_image_array).save(temp_png.name)

A typical use-case is: >>> arguments = dt.Arguments(is_label=False) >>> image_pipeline = ( … dt.LoadImage(path=temp_png.name) >> … dt.Gaussian(sigma = (1 - arguments.is_label) * 5) … ) >>> image_pipeline.bind_arguments(arguments)

>>> image = image_pipeline()  # Image with added noise.
>>> print(image.std())
5.041072178933536

Change the argument: >>> image = image_pipeline(is_label=True) # Image with no noise. >>> print(image.std()) 0.0

Remove the temporary image: >>> os.remove(temp_png.name)

For a non-mathematical dependence, create a local link to the property as follows: >>> arguments = dt.Arguments(is_label=False) >>> image_pipeline = ( … dt.LoadImage(path=temp_png.name) >> … dt.Gaussian( … is_label=arguments.is_label, … sigma=lambda is_label: 0 if is_label else 5 … ) … ) >>> image_pipeline.bind_arguments(arguments)

Keep in mind that, if any dependent property is non-deterministic, they may permanently change: >>> arguments = dt.Arguments(noise_max_sigma=5) >>> image_pipeline = ( … dt.LoadImage(path=temp_png.name) >> … dt.Gaussian( … noise_max_sigma=arguments.noise_max_sigma, … sigma=lambda noise_max_sigma: np.random.rand()*noise_max_sigma … ) … ) >>> image_pipeline.bind_arguments(arguments) >>> image_pipeline.store_properties()

>>> image = image_pipeline()
>>> print(image.get_property("sigma"))
1.1838819055669947
>>> image = image_pipeline(noise_max_sigma=0)
>>> print(image.get_property("sigma"))
0.0

As with any feature, all arguments can be passed by deconstructing the properties dict: >>> arguments = dt.Arguments(is_label=False, noise_sigma=5) >>> image_pipeline = ( … dt.LoadImage(path=temp_png.name) >> … dt.Gaussian( … sigma=lambda is_label, noise_sigma: ( … 0 if is_label else noise_sigma … ) … **arguments.properties … ) … ) >>> image_pipeline.bind_arguments(arguments)

>>> image = image_pipeline()  # Image with added noise.
>>> print(image.std())
5.002151761964336
>>> image = image_pipeline(is_label=True)  # Raw image with no noise.
>>> print(image.std())
0.0

Methods Summary

get(image, **kwargs)

Process the input image and allow property overrides.

Methods Documentation

get(image: Any, **kwargs: dict[str, Any]) Any#

Process the input image and allow property overrides.

This method does not modify the input image but provides a mechanism for overriding arguments dynamically during pipeline execution.

Parameters#

image: Any

The input image to be passed through unchanged.

**kwargs: Any

Key-value pairs for overriding pipeline properties.

Returns#

Any

The unchanged input image.