def test_augment_segmaps__kernel_size_is_two__no_keep_size(self): from imgaug.augmentables.segmaps import SegmentationMapsOnImage arr = np.int32([[0, 1, 2], [1, 2, 3]]) segmaps = SegmentationMapsOnImage(arr, shape=(6, 6, 3)) aug = self.augmenter(2, keep_size=False) segmaps_aug = aug.augment_segmentation_maps(segmaps) expected = segmaps.resize((1, 2)) assert segmaps_aug.shape == (3, 3, 3) assert segmaps_aug.arr.shape == (1, 2, 1) assert np.allclose(segmaps_aug.arr, expected.arr)
def quokka_segmentation_map(size=None, extract=None): """Return a segmentation map for the standard example quokka image. Added in 0.5.0. (Moved from ``imgaug.imgaug``.) Parameters ---------- size : None or float or tuple of int, optional See :func:`~imgaug.imgaug.quokka`. extract : None or 'square' or tuple of number or imgaug.augmentables.bbs.BoundingBox or imgaug.augmentables.bbs.BoundingBoxesOnImage See :func:`~imgaug.imgaug.quokka`. Returns ------- imgaug.augmentables.segmaps.SegmentationMapsOnImage Segmentation map object. """ # pylint: disable=invalid-name import skimage.draw # TODO get rid of this deferred import from imgaug.augmentables.segmaps import SegmentationMapsOnImage with open(_QUOKKA_ANNOTATIONS_FP, "r") as f: json_dict = json.load(f) xx = [] yy = [] for kp_dict in json_dict["polygons"][0]["keypoints"]: x = kp_dict["x"] y = kp_dict["y"] xx.append(x) yy.append(y) img_seg = np.zeros((643, 960, 1), dtype=np.int32) rr, cc = skimage.draw.polygon(np.array(yy), np.array(xx), shape=img_seg.shape) img_seg[rr, cc, 0] = 1 if extract is not None: bb = _quokka_normalize_extract(extract) img_seg = bb.extract_from_image(img_seg) segmap = SegmentationMapsOnImage(img_seg, shape=img_seg.shape[0:2] + (3, )) if size is not None: shape_resized = _compute_resized_shape(img_seg.shape, size) segmap = segmap.resize(shape_resized[0:2]) segmap.shape = tuple(shape_resized[0:2]) + (3, ) return segmap
def process_image_segmentation(image, segmap, input_w, input_h, output_w, output_h, augment): # resize the image to standard size if (input_w and input_h) or augment: segmap = SegmentationMapsOnImage(segmap, shape=image.shape) if (input_w and input_h): # Rescale image and segmaps image = ia.imresize_single_image(image, (input_w, input_h)) segmap = segmap.resize((output_w, output_h), interpolation="nearest") if augment: aug_pipe = _create_augment_pipeline() image, segmap = aug_pipe(image=image, segmentation_maps=segmap) return image, segmap.get_arr()