LambdaTransform

Qualified name: CDC.transforms.LambdaTransform

class LambdaTransform(lambda_expression)[source]

Bases: BaseTransform

Transform images using an Lambda expression.

Parameters:

lambda_expression (Callable[[np.ndarray], np.ndarray] | str) – Either a function which takes the images and perform the transformation. Or a string in the form of a python lambda expression.

Examples

Using a function:

>>> from CDC.transforms import LambdaTransform
>>> def normalize(image):
...     return image / np.max(image)
>>> transform = LambdaTransform(normalize)

Using a string:

>>> from CDC.transforms import LambdaTransform
>>> lambda_str = "lambda im: im/np.min(im) + 50"
>>> transform = LambdaTransform(lambda_str)

Methods

transform

Transform the image.

transform(image)[source]

Transform the image.

Parameters:

image (ndarray) – The image to apply the transform to.

Return type:

ndarray