Skip to content

Add augmentation for segmentation/annotation  #41

@liavassif

Description

@liavassif

Segmentation labels (annotation) are usually provided as a matrix of labels (integers).
For this task the same augmentation as the images should be performed, except interpolation should be 'nearest neighbours' rather than bilinear or similar one.
Some form of retrieving the sampled parameters (for example: rotation angle was 32 degrees) would be usefull so we could re-create the same augmentation, but with different interpolation.
Deterministic augmentation doesn't help in this case.
In the meantime, as a workaround we can use:


from imgaug import augmenters as iaa
rotate_max=30
seq = iaa.Sequential([
    iaa.Fliplr(0.5), # horizontally flip 50% of the images
],random_state=0)
rotate=iaa.Affine(rotate=(0, rotate_max),mode='edge')
rotate_nn_interpolation=iaa.Affine(rotate=(0, rotate_max),order=[0],mode='edge')
seq_nn_interpolation=seq.deepcopy()
seq.append(rotate)
seq_nn_interpolation.append(rotate_nn_interpolation)

aug_seed=0
for batch in...:
    batch_images = images[batch, :, :, :]
    batch_labels = labels[batch, :,:]
    seq.reseed(aug_seed)
    seq_nn_interpolation.reseed(aug_seed)
    batch_images=seq.augment_images(batch_images)
    batch_labels=seq_nn_interpolation.augment_images(batch_labels)
    aug_seed+=1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions