Diving Deeper…

Transformations Working with the Temporal Axis

Several basic transformations can also process the temporal axis of an the input time-lapse image sequence if desired:

  • CenterCrop and RandomCrop - to crop a shorter sub-sequence from the input sequence;

  • Pad - to pad the input sequence using a specified constant value or reflection padding to adjust the format of your data;

  • Flip and RandomFlip - to flip the input sequence to invert motion or time;

  • GaussianBlur and RandomGaussianBlur - to blur the sequence along the temporal axis to combine information from neighboring frames;

  • RemoveBackgroundGaussian - to use temporal Gaussian blurring when estimating the background images.

In addition, the ResizeTemporal transformation can change the temporal sampling rate of an input time-lapse image sequence. Please refer to its dedicated section below for more details.

Temporal Resampling

This experimental transformation allows you to change the temporal sampling rate of an input time-lapse sequence: the first and the last frames of the sequence are kept untouched, but the intermediate frames will be recomputed to reach the desired total number of time points.

The transformation, ResizeTemporal, uses optical flow to estimate motion between pairs of consecutive frames. The optical flow field is then used to warp input frames into new frames, spaced regularly between the first and last frame of the input image sequence. The optical flow is computed from a single image channel (chosen by the user) and the same flow field is then used to modify all targets in a sample.

This approach has its specialties, namely:

  • the changes between consecutive frames must be small enough to estimate motion (you can toggle the attachment parameter to reflect the change magnitude);

  • although the optical flow computation generally assumes smooth motion, the use of TV-L1 optical flow calculation allows discontinuities in the flow field and ensures robustness to noise;

  • some real-life events, such as cell division in microscopy, cannot be properly handled by the current implementation;

  • resampling of masks, especially the integer-valued ones, cannot be properly handled by the current implementation and results in artifacts (typically on object boundaries).

For more details, please see Katarína Kortánová’s Bachelor’s thesis [1].

Transformations for Microscopy Images

Photobleaching

Bio-Volumentations offer transformations for both correction and simulation of photobleaching in time-lapse fluorescence microscopy sequences. The user can choose if they prefer to suppress this phenomenon in their data or to simulate it, for instance in synthetically generated sequences.

The PhotobleachingCorrection transformation provides three methods to suppress or completely remove the photobleaching effect, implemented according to [2]. Each method is suitable for a different scenario; please see [2] for more details.

The PhotobleachingSimulation transformation simulates photobleaching as an exponential decay of image intensities over time, as described in [3].

For more details on our implementation of these transformations, please see Katarína Kortánová’s Bachelor’s thesis [1].

Light Attenuation

Similarly to photobleaching, Bio-Volumentations offer transformations for both correction and simulation of signal attenuation caused by light scattering and absorption in volumetric microscopy images. They suppress or simulate signal loss (manifested as shading) in the axial direction (i.e., along the Z axis).

Both transformations, AttenuationCorrection and AttenuationSimulation, are implemented according to [4]. This approach was developed specifically for confocal laser scanning microscopy (CLSM) images.

Alongside the transformations themselves, we also provide a Jupyter Notebook where you can easily test the effect of the transformations with your data and toggle the input parameters such as \(\alpha\) (fluorescence_efficiency) and \(\epsilon_{\lambda}\) (attenuation_coefficient).

For more details on our implementation of these transformations, please see Katarína Kortánová’s Bachelor’s thesis [1].

Background Subtraction

The RemoveBackgroundGaussian transformation performs background subtraction in images with bright objects on dark background (such as fluorescence microscopy images) or, vice versa, dark objects on bright background. The background image is created using Gaussian blurring whose strength must be set by the user according to the size of objects in the image. The background image then is subtracted from the original image (or, in the case of dark objects, the original image is subtracted from the background image).

Even though this transformation was motivated by processing microscopy images, it does not rely on any microscopy-specific phenomena, and can thus be used with images of any kind.

Bibliography

[1] KORTÁNOVÁ, Katarína. Preprocessing and augmentation of time-lapse biomedical image data with annotations. Online. Bachelor’s thesis. Brno: Masaryk University, Faculty of Informatics. 2026. Available from: https://is.muni.cz/th/cujlg/?lang=en.

[2] MIURA, Kota. Bleach correction ImageJ plugin for compensating the photobleaching of time-lapse sequences. F1000Res. 2020, vol. 9, p. 1494. issn 2046-1402. Available from doi: 10.12688/f1000research.27171.1.

[3] SVOBODA, David; ULMAN, Vladimir; MATYSKA, Ludek, et al. On proper simulation of phenomena influencing image formation in fluorescence microscopy. In: 2014 IEEE International Conference on Image Processing (ICIP). Paris, France: IEEE, 2014, pp. 3944–3948. isbn 978-1-4799-5751-4. Available from doi: 10.1109/ICIP.2014.7025801.

[4] OHSER, J.; HAAS, P.; FAHRBACH, F., et al. Attenuation correction for confocal laser scanning microscopy and its application in chromatography. Journal of Microscopy. 2020, vol. 278, no. 2, pp. 76–88. issn 0022-2720, issn 1365-2818. Available from doi: 10.1111/jmi.12888.

Bounding Box Formats

This section showcases how a single bounding box is represented in different formats. Suppose we have a time-lapse image sequence of shape [1, 10, 10, 10, 20] (i.e., with a single channel and 20 time points) and a bounding box stretching from pixel [2, 3, 5] to pixel [6, 5, 8] in time point 14.

voc: absolute coordinates, minimal and maximal corners of the bounding box

bbox = (2, 3, 5), (6, 5, 8), 14

coco: absolute coordinates, minimal corner and depth, height, width of the bounding box

bbox = (2, 3, 5), (4, 2, 3), 14

albumentations: normalized coordinates, minimal and maximal corners of the bounding box

bbox = (0.2, 0.3, 0.5), (0.6, 0.5, 0.8), 14

yolo: normalized coordinates, central point and depth, height, width of the bounding box

bbox = (0.4 0.4 0.65), (0.4 0.2 0.3), 14

Optionally, we can specify a class label as the fourth parameter of the bounding box:

bbox = (2, 3, 5), (6, 5, 8), 14, 'class_label'

If you are wondering which bbox format we are using internally… it is voc. The list of tuples representing a list of bounding boxes you input to the transformation pipeline (the instantiated Compose object) is, in fact, first converted to our internal representation that is based on the voc format right before the user-defined transformations are applied. The result is then converted back to a list of tuples in the original bbox format right before returning the new list of bboxes from the Compose object to the user.

Runtime

The execution times of individual transformations from our library and their comparison to other libraries capable of processing volumetric image data are available at the project’s GitLab page.

Using Bio-Volumentations with automatic augmentation frameworks

Bio-Volumentations can also be used with existing automatic augmentation frameworks. We prepared examples of using our library with AutoAugment and RandAugment - they are available in the respective file at GitLab.

Adding a Custom Transformation

Each transformation inherits from the Transform class. You can thus easily implement your own transformations and use them with this library. You can check our implementations to see how this can be done; for example, Flip can be implemented as follows:

import numpy as np
from typing import List
from bio_volumentations import DualTransform
import my_backend_functions  # a package with backend functionality (such as keypoint/bbox flipping)

class Flip(DualTransform):
    # Initialize the transform
    def __init__(self, axes: List[int] = None, always_apply=False, p=1):
        super().__init__(always_apply, p)
        self.axes = axes

    # Transform the image
    def apply(self, img, **params):
        return np.flip(img, params["axes"])

    # Transform the int-valued mask
    def apply_to_mask(self, mask, **params):
        return np.flip(mask, axis=[item - 1 for item in params["axes"]])  # Mask has no channels

    # Transform the float-valued mask - no need to implement. By default, apply_to_float_mask() uses
    # the implementation of apply_to_mask(), unless it is overridden (see the implementation of DualTransform).

    # Transform the keypoints
    def apply_to_keypoints(self, keypoints, **params):
        return my_backend_functions.flip_keypoints(keypoints, axes=params['axes'], img_shape=params['img_shape'])

    # Transform the bounding boxes
    def apply_to_bboxes(self, keypoints, **params):
        return my_backend_functions.flip_bboxes(keypoints, axes=params['axes'], img_shape=params['img_shape'])

    # Set transformation parameters. This is useful especially for RandomXXX transforms
    # to ensure consistent transformation of samples with multiple targets.
    def get_params(self, **data):
        axes = [1, 2, 3] if self.axes is None else self.axes
        img_shape = np.array(data['image'].shape[1:4])
        return {"axes": axes, "img_shape": img_shape}