Clip#

class deeptrack.optical.math.Clip(min: float | Callable[[...], float] = -inf, max: float | Callable[[...], float] = inf, **kwargs: Any)#

Bases: Feature

Clip values of an array to a specified range.

This feature applies elementwise clipping such that all values in the input are constrained to the interval [min, max].

This operation is purely pointwise and does not interpret dimensions (e.g., spatial or channel axes). The same transformation is applied independently to every element.

Parameters#

min: float, optional

Lower bound. Values below this will be set to min. Defaults to -inf.

max: float, optional

Upper bound. Values above this will be set to max. Defaults to +inf.

Returns#

np.ndarray or torch.Tensor

Clipped array with the same shape and dtype as the input.

Methods#

get(image, min, max, **kwargs) -> np.ndarray | torch.Tensor

Clips the input image between min and max.

Examples#

>>> import deeptrack as dt

Create an input image:

>>> import numpy as np
>>>
>>> input_image = np.asarray([[10, 4], [4, -10]])

Define a clipper feature:

>>> clipper = dt.Clip(min=0, max=5)
>>> output_image = clipper(input_image)
>>> output_image
array([[5, 4],
       [4, 0]])

Methods Summary

get(image, min, max, **kwargs)

Clips the input image within the specified values.

Methods Documentation

get(image: ndarray | Tensor, min: float, max: float, **kwargs: Any) ndarray | Tensor#

Clips the input image within the specified values.

This method clips the input image within the specified minimum and maximum values.

Parameters#

image: array

Input image to clip.

min: float

Minimum allowed value.

max: float

Maximum allowed value.

Returns#

array

The clipped image.