The previous two chapters presented the most basic usage of imgaug, as well as a more comprehensive presentation of various enhancement methods. Here we introduce data enhancement methods in the segmentation problem. In the classification problem, the input is an image and the output is a category. In this kind of problem, we only need to enhance the image and do not need to change the label. In the segmentation problem, when the image used in training is flipped or distorted, the label should also be flipped or distorted accordingly. Therefore, in the process of enhancement, not only the image should be processed, but also the segmented label should be processed in the same way. To make the same processing for images and labels, we need to determine the enhancement method for one image and apply it to the image and labels in sequence. Here we need to use the function seq.to_deterministic() to get a deterministic enhancement function. To know how to use it, we first need to have two variables that record the original image and the split label respectively, called image and Segmap. The implementation method is as follows. We use a picture of the system to enhance it. Here we improve it on the basis of the tutorial of the original website, because there is no output of intermediate steps in the manual that can be used to train the network. Missing is a step to convert SegmentationMapOnImage data to Numpy data, which we have added here. Our final result is shown below. Finally, the method of segmentation enhancement is still under development in the imgaug library. Some tests have not been completed, but it can be used normally at present. import imgaug as ia from imgaug import augmenters as iaa import imageio import numpy as np ia.seed(1) image = Ia. Quokka (size=(128, 128), extract=”square”) Segmap = Np.zeros ((128, 128), dType = Np.int32) 30:45] = 2 segmap[10:25, 70:85] = 3 segmap[10:110, 5:10] = 4 segmap[118:123, Pleasure: 0] = 5 # converts images to SegmentationMapOnImage type segmap = ia. SegmentationMapOnImage (segmap, shape = image shape, Nb_classes =1+5) # define data enhancement methods seq = IAA. Sequential([IAA.Dropout ([0.05, 0.2]), Sharpen the image.Affine(Sharpen =(-45, 45)), # rotate by -45 to 45 degrees (affects heatmaps) iaa.ElasticTransformation(alpha=50, Sigma =5) # apply water effect (affects heatmaps)], random_order=True) images_Aug = [] segmaps_Aug = [] Data enhancement for multiple graphs. Seq_det = seq.to_deterministic() # determine a data enhanced sequence images_Aug = seq_det.augment_image(image) # apply the method to the original image segmaps_Aug = Seq_det.augment_segmentation_maps ([Segmap])[0].get_arr_int().astype(np.uint8) # And converted into segmaps_aug = np type ia. SegmentationMapOnImage (segmaps_aug, shape = image shape, Nb_classes =1+5) nb_classes=1+5) Cells = [] cells.append(image) cells.append(segmap.draw_on_image(image)) cells.append(images_Aug) cells.append(segmaps_aug.draw_on_image(images_aug)) cells.append(segmaps_aug.draw(size=images_aug.shape[:2])) grid_image = ia.draw_grid(cells, cols=5) imageio.imwrite(“example_segmaps.jpg”, grid_image)

Learn more about Python at gzitcast