deeptrack.optical.augmentations Module#
Augmentation utilities.
This module provides feature classes for applying spatial transformations and augmentations to images, arrays, scattered fields, or scattered volumes. Supported transformations include flipping, affine transformations, elastic deformations, cropping, and padding.
When used in a training pipeline, these augmentations synthetically increase the amount of training data for data-driven learning models.
Key Features#
General Augmentations
Basic image augmentation methods to perform transformations such as flipping an image horizontally (left-right), vertically (up-down), or along the diagonal.
Advanced Augmentations
For users who require more control over the image transformations. Advanced augmentation methods allow operations like translation, scaling, rotation, and shearing. These operations can be customized with user-specified parameters (e.g., degrees of rotation, scaling factors), giving flexibility in how the images are transformed.
Caching
To avoid redundant computations, the Reuse feature caches a fixed number of outputs (storage) and reuses each cached output a specified number of times (uses) before recomputing.
Cropping
Enables different methods to crop an image. Region-specific cropping, cropping based on multiples of the height/width of an image, and crop to remove empty space at edges of an image.
Padding
Padding operations allow you to extend the shape of an image by adding extra pixels around its edges, which is essential for ensuring that the shape of the image stays consistent.
Module Structure#
Classes:
Augmentation: Base class for augmentations.
Reuse: Stores and reuses feature outputs.
FlipLR: Flips image left to right.
FlipUD: Flips an image up-down.
FlipDiagonal: Flips image along the diagonal.
Affine: Translation, scaling, rotation, shearing.
ElasticTransformation: Transform using a displacement field.
Crop: Crop regions of an image.
CropToMultiplesOf: Crops image until height/width is multiple of a value.
CropTight: Crops an array to remove empty space along its edges.
Pad: Pads image with values.
PadToMultiplesOf: Pad images until height/width is a multiple of a value.
Examples#
>>> import deeptrack as dt
Flip an image of a particle up-down then flips left-right:
>>> particle = dt.PointParticle(intensity=1)
>>> optics = dt.Fluorescence()
>>> image = optics(particle) >> dt.FlipUD(p=1.0) >> dt.FlipLR(p=1.0)
>>> image.plot();
Reuse the output of a pipeline twice, augmented randomly by FlipLR.
>>> import matplotlib.pyplot as plt
>>>
>>> particle = dt.PointParticle(intensity=1)
>>> optics = dt.Fluorescence()
>>> base = optics(particle)
>>> pipeline = dt.Reuse(base, uses=2) >> dt.FlipLR()
>>>
>>> fig, ax = plt.subplots(1, 8, figsize=(12, 3))
>>> for i in range(8):
>>> img = pipeline.new()
>>> ax[i].imshow(img, cmap="gray")
>>> ax[i].axis("off")
>>> plt.tight_layout()
>>> plt.show()
Classes#
|
Base class for augmentation features. |
|
Cache and reuse the output of another feature. |
|
Flip images left-right. |
|
Flip images up-down. |
|
Flip images along the diagonal. |
|
Apply affine transformations to images. |
|
Apply elastic distortions to images. |
|
Crop a region of an image. |
|
Crop images so their dimensions are multiples of a given value. |
|
Crop an array to remove empty space. |
|
Pad an image by adding extra pixels along specified axes. |
|
Pad images so their dimensions become multiples of a given value. |