albumentations_3d
is an small augmentation library with an API similar to albumentations but with specific support for 3D images in segmentation-based tasks. This package allows for paired augmentations of images
, masks
, and weight maps
.
Augmentations such as blur will only be applied to image
. Augmentations such as elastic_deform
will be applied to image
, mask
and weight_map
.
This library was used in training a UNet edge detector for instance segmentation of the C. elegans germline, found here.
See the example notebook.
Flip data on a random axis
augmentor = aug.Flip(
p=0.5 # Probability to apply augmentation
)
aug_data = augmentor(**data, targets=[["image"], ["mask"], ["weight_map"]])
Apply a random Gaussian blur within a given sigma range
augmentor = aug.RandomGuassianBlur(
sigma_range=[0, 5],
p=1
)
Apply a paired elastic deformation on images, masks and weight maps. Supports multichannel images. Elastic deform implementation uses elasticdeform which is fast, so deformation can be applied at training time.
augmentor = aug.ElasticDeform(
channel_axis=0, # If the input image is multichannel, note its axis here
sigma=25, # Deformation sigma
points=3, # Deformation grid dimensions
mode="mirror", # Border mode
axis=(1, 2), # Define (spatial) axes to perform deformation. (1, 2) for x and y only since z is shallow. Apply to all axes with (0, 1, 2)
p=1,
)
Convert masks into edges only for training an edge detector. Uses skimage find_boundaries
.
augmentor = aug.LabelsToEdges(
mode="inner", # Boundary mode
connectivity=2 # Pixel connectivity to draw boundary
)
String together multiple augmentations
augmentor = aug.Compose(
[
aug.LabelsToEdges(mode="inner"),
aug.EdgeMaskWmap(
edge_multiplier=1,
wmap_multiplier=5,
invert_wmap=False
)],
targets=[["image"], ["mask"], ["weight_map"]]
)
Mask only regions that are defined by the target mask. Additionally, you can invert the weight map, multiply edge masks and weight maps themselves.
augmentor = aug.Compose(
[
aug.Flip(p=0.5),
aug.RandomGuassianBlur(p=0.5),
aug.ElasticDeform(channel_axis=0, sigma=5, p=0.5),
aug.LabelsToEdges(mode="inner"),
aug.EdgeMaskWmap(
edge_multiplier=1,
wmap_multiplier=5,
invert_wmap=False
)],
targets=[["image"], ["mask"], ["weight_map"]]
)