biapy.data.generators.pair_data_3D_generator

3D paired image and mask data generator for BiaPy.

This module provides the Pair3DImageDataGenerator class, which generates batches of 3D images and their corresponding masks with on-the-fly augmentation.

class biapy.data.generators.pair_data_3D_generator.Pair3DImageDataGenerator(zflip: bool = False, **kwars)[source]

Bases: PairBaseDataGenerator

Custom 3D data generator. This generator will yield an image and its corresponding mask.

Parameters:

zflip (bool, optional) – To activate flips in z dimension.

apply_transform(image: ndarray[tuple[int, ...], dtype[_ScalarType_co]], mask: ndarray[tuple[int, ...], dtype[_ScalarType_co]], e_im: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | None = None, e_mask: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | None = None) Tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]], ndarray[tuple[int, ...], dtype[_ScalarType_co]]][source]

Transform the input image and its mask at the same time with one of the selected choices based on a probability.

Parameters:
  • image (4D Numpy array) – Image to transform. E.g. (z, y, x, channels).

  • mask (4D Numpy array) – Mask to transform. E.g. (z, y, x, channels).

  • e_im (4D Numpy array) – Extra image to help transforming image. E.g. (z, y, x, channels).

  • e_mask (4D Numpy array) – Extra mask to help transforming mask. E.g. (z, y, x, channels).

Returns:

  • image (4D Numpy array) – Transformed image. E.g. (z, y, x, channels)`.

  • mask (4D Numpy array) – Transformed image mask. E.g.``(z, y, x, channels)``.

save_aug_samples(img, mask, orig_images, i, pos, out_dir)[source]

Save augmented and original samples for inspection.

Parameters:
  • img (4D Numpy array) – Augmented image sample. E.g. (z, y, x, channels).

  • mask (4D Numpy array) – Augmented mask sample. E.g. (z, y, x, channels).

  • orig_images (dict) – Dictionary containing original image and mask under keys “o_x” and “o_y”.

  • i (int) – Index of the augmented sample.

  • pos (int) – Index of the sample in the dataset.

  • out_dir (str) – Directory to save the images.