features

Base class Feature and structural features

Provides classes and tools for creating and interacting with features.

Classes

Feature

Base abstract class.

StructuralFeature

Abstract extension of feature for interactions between features.

Branch

Implementation of StructuralFeature that resolves two features sequentially.

Probability

Implementation of StructuralFeature that randomly resolves a feature with a certain probability.

Duplicate

Implementation of StructuralFeature that sequentially resolves an integer number of deep-copies of a feature.

Module classes

Branch

class deeptrack.features.Branch(feature_1: deeptrack.features.Feature, feature_2: deeptrack.features.Feature, *args, **kwargs)

Resolves to features sequentially :param feature_1: :type feature_1: Feature :param feature_2: :type feature_2: Feature

get(image, feature_1, feature_2, **kwargs)

Resolves feature_1 and feature_2 sequentially

ConditionalSetFeature

class deeptrack.features.ConditionalSetFeature(on_false: deeptrack.features.Feature = None, on_true: deeptrack.features.Feature = None, condition='is_label', **kwargs)

Conditionally resolves one of two features

Parameters
  • on_false (Feature) – Feature to resolve if the conditional property is false

  • on_true (Feature) – Feature to resolve if the conditional property is true

  • condition (str) – The name of the conditional property

get(image, *, on_false, on_true, condition, **kwargs)

Method for altering an image Abstract method that define how the feature transforms the input. The current value of all properties will be passed as keyword arguments.

Parameters
  • image (Image or List[Image]) – The Image or list of images to transform

  • **kwargs – The current value of all properties in properties as well as any global arguments.

Returns

The transformed image or list of images

Return type

Image or List[Image]

ConditionalSetProperty

class deeptrack.features.ConditionalSetProperty(feature: deeptrack.features.Feature, condition='is_label', **kwargs)

Conditionally overrides the properties of child features

Parameters
  • feature (Feature) – The child feature

  • condition (str) – The name of the conditional property

  • **kwargs – Properties to be used if condition is True

get(image, feature, condition, **kwargs)

Method for altering an image Abstract method that define how the feature transforms the input. The current value of all properties will be passed as keyword arguments.

Parameters
  • image (Image or List[Image]) – The Image or list of images to transform

  • **kwargs – The current value of all properties in properties as well as any global arguments.

Returns

The transformed image or list of images

Return type

Image or List[Image]

Duplicate

class deeptrack.features.Duplicate(feature: deeptrack.features.Feature, num_duplicates: int, *args, **kwargs)

Resolves copies of a feature sequentially Creates num_duplicates copies of the feature and resolves them sequentially

Parameters
  • feature (Feature) – The feature to duplicate

  • num_duplicates (int) – The number of duplicates to create

get(image, features: List[deeptrack.features.Feature], **kwargs)

Resolves each feature in features sequentially

update(**kwargs)

Updates the state of all properties.

Parameters

**kwargs – Arguments that will be passed to the Property method update().

Returns

Return type

self

Feature

class deeptrack.features.Feature(*args: dict, **kwargs)

Base feature class. Features define the image generation process. All features operate on lists of images. Most features, such as noise, apply some tranformation to all images in the list. This transformation can be additive, such as adding some Gaussian noise or a background illumination, or non-additive, such as introducing Poisson noise or performing a low-pass filter. This transformation is defined by the method get(image, **kwargs), which all implementations of the class Feature need to define.

Whenever a Feature is initiated, all keyword arguments passed to the constructor will be wrapped as a Property, and stored in the properties field as a PropertyDict. When a Feature is resolved, the current value of each property is sent as input to the get method.

Parameters
  • *args (dict, optional) – Dicts passed as nonkeyword arguments will be deconstructed to key-value pairs and included in the field properties in the same way as keyword arguments.

  • **kwargs – All Keyword arguments will be wrapped as instances of Property and included in the field properties.

properties

A dict that contains all keyword arguments passed to the constructor wrapped as Distributions. A sampled copy of this dict is sent as input to the get function, and is appended to the properties field of the output image.

Type

dict

__list_merge_strategy__

Controls how the output of .get(image, **kwargs) is merged with the input list. It can be MERGE_STRATEGY_OVERRIDE (0, default), where the input is replaced by the new list, or MERGE_STRATEGY_APPEND (1), where the new list is appended to the end of the input list.

Type

int

__distributed__

Controls whether .get(image, **kwargs) is called on each element in the list separately (__distributed__ = True), or if it is called on the list as a whole (__distributed__ = False).

Type

bool

__property_memorability__

Controls whether to store the features properties to the Image. Values 1 or lower will be included by default.

abstract get(image: deeptrack.image.Image, **kwargs) → deeptrack.image.Image

Method for altering an image Abstract method that define how the feature transforms the input. The current value of all properties will be passed as keyword arguments.

Parameters
  • image (Image or List[Image]) – The Image or list of images to transform

  • **kwargs – The current value of all properties in properties as well as any global arguments.

Returns

The transformed image or list of images

Return type

Image or List[Image]

plot(input_image: deeptrack.image.Image = None, resolve_kwargs: dict = None, interval: float = None, **kwargs)

Visualizes the output of the feature Resolves the feature and visualizes the result. If the output is an Image, show it using pyplot.imshow. If the output is a list, create an Animation. For notebooks, the animation is played inline using to_jshtml(). For scripts, the animation is played using the matplotlib backend.

Any parameters in kwargs will be passed to pyplot.imshow.

Parameters
  • input_image (Image or List[Image], optional) – Passed as argument to resolve call

  • resolve_kwargs (dict, optional) – Passed as kwarg arguments to resolve call

  • interval (float) – The time between frames in animation in ms. Default 33.

  • kwargs – keyword arguments passed to the method pyplot.imshow()

resolve(image_list: deeptrack.image.Image = None, **global_kwargs)

Creates the image. Transforms the input image by calling the method get() with the correct inputs. The properties of the feature can be overruled by passing a different value as a keyword argument.

Parameters
  • image_list (Image or List[Image], optional) – The Image or list of images to be transformed.

  • **global_kwargs – Set of arguments that are applied globally. That is, every feature in the set of features required to resolve an image will receive these keyword arguments.

Returns

The resolved image

Return type

Image or List[Image]

sample(**kwargs) → deeptrack.features.Feature

Returns the feature

update(**kwargs) → deeptrack.features.Feature

Updates the state of all properties.

Parameters

**kwargs – Arguments that will be passed to the Property method update().

Returns

Return type

self

Label

class deeptrack.features.Label(output_shape=None, **kwargs)

Outputs the properties of this features.

Can be used to extract properties in a feature set and combine them into a numpy array.

Parameters

output_shape (tuple of ints) – Reshapes the output to this shape

get(image, output_shape=None, hash_key=None, **kwargs)

Method for altering an image Abstract method that define how the feature transforms the input. The current value of all properties will be passed as keyword arguments.

Parameters
  • image (Image or List[Image]) – The Image or list of images to transform

  • **kwargs – The current value of all properties in properties as well as any global arguments.

Returns

The transformed image or list of images

Return type

Image or List[Image]

Lambda

class deeptrack.features.Lambda(function, **kwargs)

Calls a custom functions.

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

function (Callable[Image or list of Image]) – Function that takes the current image as first input

get(image, function, **kwargs)

Method for altering an image Abstract method that define how the feature transforms the input. The current value of all properties will be passed as keyword arguments.

Parameters
  • image (Image or List[Image]) – The Image or list of images to transform

  • **kwargs – The current value of all properties in properties as well as any global arguments.

Returns

The transformed image or list of images

Return type

Image or List[Image]

LoadImage

class deeptrack.features.LoadImage(path, load_options={}, **kwargs)

Loads an image from disk.

Cycles through file-readers numpy, pillow and opencv2 to open the image file.

Parameters
  • path (str) – Path to image to load

  • load_options (dict) – Options passed to the file reader

Raises

IOError – If no file reader could parse the file or the file doesn’t exist.

get(*ign, path, load_options, **kwargs)

Method for altering an image Abstract method that define how the feature transforms the input. The current value of all properties will be passed as keyword arguments.

Parameters
  • image (Image or List[Image]) – The Image or list of images to transform

  • **kwargs – The current value of all properties in properties as well as any global arguments.

Returns

The transformed image or list of images

Return type

Image or List[Image]

Probability

class deeptrack.features.Probability(feature: deeptrack.features.Feature, probability: float, *args, **kwargs)

Resolves a feature with a certain probability

Parameters
  • feature (Feature) – Feature to resolve

  • probability (float) – Probability to resolve

get(image, feature: deeptrack.features.Feature, probability: float, random_number: float, **kwargs)

Resolves feature if random_number is less than probability

StructuralFeature

class deeptrack.features.StructuralFeature(*args: dict, **kwargs)

Provides the structure of a feature-set Feature with __property_verbosity__ = 2 to avoid adding it to the list of properties, and __distributed__ = False to pass the input as-is.