Skip to content

Paired augmentations (image, mask, weight map) for 3D multichannel images

Notifications You must be signed in to change notification settings

COBA-NIH/albumentations_3d

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

albumentations_3d

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.

Examples

See the example notebook.

Flip

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"]])

flip

Blur

Apply a random Gaussian blur within a given sigma range

augmentor = aug.RandomGuassianBlur(
    sigma_range=[0, 5], 
    p=1
    )

blur

ElasticDeform

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,
    )

elastic_deform

LabelsToEdges

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
    )

to_edges

Compose

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"]]
    )

Apply weight map to masks

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"]]
    )

apply_weight

About

Paired augmentations (image, mask, weight map) for 3D multichannel images

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages