This module defines tools for image data preprocessing and real-time data augmentation that is used to train a model.
Example image and mask
We will use an example image and mask to guide through the documentation.
Plot example image and mask
image = imageio.imread(path/'images'/'01.png')
mask = imageio.imread(path/'labels'/'01_mask.png')
show(image, mask)
Supported segmentation mask types:
Class labels: pixel annotations of classes (e.g., 0 for background and 1...n for positive classes)
Instance labels: pixel annotation of belonggig to different instance (e.g., 0 for background, 1 for first ROI, 2 for second ROI, etc.).
_show(mask, inst_labels)
The provided segmentation masks are preprocessed to
- convert instance labels to class labels
- draw small ridges between touching instances (optional)
Arguments in preprocess_masks
:
clabels
: class labels (segmentation mask),instlabels
: instance labels (segmentation mask),num_classes
(int) = number of classes
tst1 = preprocess_mask(mask, remove_connectivity=False)
tst2 = preprocess_mask(mask, remove_connectivity=True)
_show(tst1,tst2)
ind = (slice(200,230), slice(230,260))
print('Zoom in on borders:')
_show(tst1[ind], tst2[ind])
Deformation field class to ensure that all augmentations are performed equally on images, masks, and weights. Implemented augmentations are
- rotation
- mirroring
- random deformation
Original Image
tst = DeformationField(shape=(260, 260), scale=1, scale_range=(0.7, 1.4))
show(tst.apply(image, offset=(270,270)),
tst.apply(mask, offset=(270,270)))
Add mirroring
tst = DeformationField()
tst.mirror((1,1))
show(tst.apply(image, offset=(270,270)),
tst.apply(mask, offset=(270,270)))