def test_one_image(self): rng = iarandom.RNG(0) image = rng.integers(0, 256, size=(256, 256, 3), dtype=np.uint8) debug_image = iaa.draw_debug_image([image]) assert self._image_contains(image, debug_image)
def test_two_images(self): rng = iarandom.RNG(0) images = rng.integers(0, 256, size=(2, 256, 256, 3), dtype=np.uint8) debug_image = iaa.draw_debug_image(images) assert self._image_contains(images[0, ...], debug_image) assert self._image_contains(images[1, ...], debug_image)
def test_one_image_float32(self): rng = iarandom.RNG(0) image = rng.random(size=(256, 256, 3)).astype(np.float32) debug_image = iaa.draw_debug_image([image]) assert self._image_contains((image * 255).astype(np.uint8), debug_image)
def test_two_images_of_different_sizes(self): rng = iarandom.RNG(0) image1 = rng.integers(0, 256, size=(256, 256, 3), dtype=np.uint8) image2 = rng.integers(0, 256, size=(512, 256, 3), dtype=np.uint8) debug_image = iaa.draw_debug_image([image1, image2]) assert self._image_contains(image1, debug_image) assert self._image_contains(image2, debug_image)
def test_one_image_float32_and_heatmap(self): rng = iarandom.RNG(0) image = rng.random(size=(256, 256, 3)).astype(np.float32) heatmap = np.zeros((256, 256, 1), dtype=np.float32) heatmap[128-25:128+25, 128-25:128+25] = 1.0 heatmap = ia.HeatmapsOnImage(heatmap, shape=image.shape) image1_w_overlay = heatmap.draw_on_image( (image*255).astype(np.uint8))[0] debug_image = iaa.draw_debug_image([image], heatmaps=[heatmap]) assert self._image_contains((image * 255).astype(np.uint8), debug_image) assert self._image_contains(image1_w_overlay, debug_image)
def test_two_images_and_heatmaps(self): rng = iarandom.RNG(0) images = rng.integers(0, 256, size=(2, 256, 256, 3), dtype=np.uint8) heatmap = np.zeros((256, 256, 1), dtype=np.float32) heatmap[128 - 25:128 + 25, 128 - 25:128 + 25] = 1.0 heatmap1 = ia.HeatmapsOnImage(np.copy(heatmap), shape=images[0].shape) heatmap2 = ia.HeatmapsOnImage(1.0 - heatmap, shape=images[1].shape) image1_w_overlay = heatmap1.draw_on_image(images[0])[0] image2_w_overlay = heatmap2.draw_on_image(images[1])[0] debug_image = iaa.draw_debug_image(images, heatmaps=[heatmap1, heatmap2]) assert self._image_contains(images[0, ...], debug_image) assert self._image_contains(images[1, ...], debug_image) assert self._image_contains(image1_w_overlay, debug_image) assert self._image_contains(image2_w_overlay, debug_image)
def test_two_images_and_keypoints(self): rng = iarandom.RNG(0) images = rng.integers(0, 256, size=(2, 256, 256, 3), dtype=np.uint8) kps = [] for x in np.linspace(0, 256, 10): for y in np.linspace(0, 256, 10): kps.append(ia.Keypoint(x=x, y=y)) kpsoi1 = ia.KeypointsOnImage(kps, shape=images[0].shape) kpsoi2 = kpsoi1.shift(x=20) image1_w_overlay = kpsoi1.draw_on_image(images[0]) image2_w_overlay = kpsoi2.draw_on_image(images[1]) debug_image = iaa.draw_debug_image(images, keypoints=[kpsoi1, kpsoi2]) assert self._image_contains(images[0, ...], debug_image) assert self._image_contains(images[1, ...], debug_image) assert self._image_contains(image1_w_overlay, debug_image) assert self._image_contains(image2_w_overlay, debug_image)
def test_two_images_and_bounding_boxes(self): rng = iarandom.RNG(0) images = rng.integers(0, 256, size=(2, 256, 256, 3), dtype=np.uint8) bbs = [] for x in np.linspace(0, 256, 5): for y in np.linspace(0, 256, 5): bbs.append(ia.BoundingBox(x1=x, y1=y, x2=x + 20, y2=y + 20)) bbsoi1 = ia.BoundingBoxesOnImage(bbs, shape=images[0].shape) bbsoi2 = bbsoi1.shift(left=20) image1_w_overlay = bbsoi1.draw_on_image(images[0]) image2_w_overlay = bbsoi2.draw_on_image(images[1]) debug_image = iaa.draw_debug_image(images, bounding_boxes=[bbsoi1, bbsoi2]) assert self._image_contains(images[0, ...], debug_image) assert self._image_contains(images[1, ...], debug_image) assert self._image_contains(image1_w_overlay, debug_image) assert self._image_contains(image2_w_overlay, debug_image)
def test_two_images_and_line_strings(self): rng = iarandom.RNG(0) images = rng.integers(0, 256, size=(2, 32, 32, 3), dtype=np.uint8) ls = [] for x in np.linspace(0, 256, 4): for y in np.linspace(0, 256, 4): ls.append( ia.LineString([(x, y), (x + 20, y), (x + 20, y + 20), (x, y + 20)])) lsoi1 = ia.LineStringsOnImage(ls, shape=images[0].shape) lsoi2 = lsoi1.deepcopy() image1_w_overlay = lsoi1.draw_on_image(images[0]) image2_w_overlay = lsoi2.draw_on_image(images[1]) debug_image = iaa.draw_debug_image(images, line_strings=[lsoi1, lsoi2]) assert self._image_contains(images[0, ...], debug_image) assert self._image_contains(images[1, ...], debug_image) assert self._image_contains(image1_w_overlay, debug_image) assert self._image_contains(image2_w_overlay, debug_image)
def test_two_images_and_polygons(self): rng = iarandom.RNG(0) images = rng.integers(0, 256, size=(2, 32, 32, 3), dtype=np.uint8) polys = [] for x in np.linspace(0, 256, 4): for y in np.linspace(0, 256, 4): polys.append( ia.Polygon([(x, y), (x + 20, y), (x + 20, y + 20), (x, y + 20)])) psoi1 = ia.PolygonsOnImage(polys, shape=images[0].shape) psoi2 = psoi1.shift(left=20) image1_w_overlay = psoi1.draw_on_image(images[0]) image2_w_overlay = psoi2.draw_on_image(images[1]) debug_image = iaa.draw_debug_image(images, polygons=[psoi1, psoi2]) assert self._image_contains(images[0, ...], debug_image) assert self._image_contains(images[1, ...], debug_image) assert self._image_contains(image1_w_overlay, debug_image) assert self._image_contains(image2_w_overlay, debug_image)
def test_temp_directory(self): with TemporaryDirectory() as folder_path: image = iarandom.RNG(0).integers(0, 256, size=(256, 256, 3), dtype=np.uint8) aug = iaa.SaveDebugImageEveryNBatches(folder_path, 10) for _ in np.arange(20): _ = aug(image=image) expected = iaa.draw_debug_image([image]) path1 = os.path.join(folder_path, "batch_000000.png") path2 = os.path.join(folder_path, "batch_000010.png") path_latest = os.path.join(folder_path, "batch_latest.png") assert len(list(os.listdir(folder_path))) == 3 assert os.path.isfile(path1) assert os.path.isfile(path2) assert os.path.isfile(path_latest) assert np.array_equal(imageio.imread(path1), expected) assert np.array_equal(imageio.imread(path2), expected) assert np.array_equal(imageio.imread(path_latest), expected)
def test_mocked(self): class _DummyDestination(debuglib._IImageDestination): def __init__(self): self.received = [] def receive(self, image): self.received.append(np.copy(image)) image = iarandom.RNG(0).integers(0, 256, size=(256, 256, 3), dtype=np.uint8) destination = _DummyDestination() aug = iaa.SaveDebugImageEveryNBatches(destination, 10) for _ in np.arange(20): _ = aug(image=image) expected = iaa.draw_debug_image([image]) assert len(destination.received) == 2 assert np.array_equal(destination.received[0], expected) assert np.array_equal(destination.received[1], expected)
def test_two_images_and_heatmaps__multichannel(self): rng = iarandom.RNG(0) images = rng.integers(0, 256, size=(2, 256, 256, 3), dtype=np.uint8) heatmap = np.zeros((256, 256, 2), dtype=np.float32) heatmap[100-25:100+25, 100-25:100+25, 0] = 1.0 heatmap[200-25:200+25, 200-25:200+25, 1] = 1.0 heatmap1 = ia.HeatmapsOnImage(np.copy(heatmap), shape=images[0].shape) heatmap2 = ia.HeatmapsOnImage(1.0 - heatmap, shape=images[1].shape) image1_w_overlay_c1, image1_w_overlay_c2 = \ heatmap1.draw_on_image(images[0]) image2_w_overlay_c1, image2_w_overlay_c2 = \ heatmap2.draw_on_image(images[1]) debug_image = iaa.draw_debug_image(images, heatmaps=[heatmap1, heatmap2]) assert self._image_contains(images[0, ...], debug_image) assert self._image_contains(images[1, ...], debug_image) assert self._image_contains(image1_w_overlay_c1, debug_image) assert self._image_contains(image1_w_overlay_c2, debug_image) assert self._image_contains(image2_w_overlay_c1, debug_image) assert self._image_contains(image2_w_overlay_c2, debug_image)
def test_two_images_and_segmaps(self): rng = iarandom.RNG(0) images = rng.integers(0, 256, size=(2, 256, 256, 3), dtype=np.uint8) sm1 = np.zeros((256, 256, 1), dtype=np.int32) sm1[128 - 25:128 + 25, 128 - 25:128 + 25] = 1 sm2 = np.zeros((256, 256, 1), dtype=np.int32) sm2[64 - 25:64 + 25, 64 - 25:64 + 25] = 2 sm2[192 - 25:192 + 25, 192 - 25:192 + 25] = 3 segmap1 = ia.SegmentationMapsOnImage(sm1, shape=images[0].shape) segmap2 = ia.SegmentationMapsOnImage(sm2, shape=images[1].shape) image1_w_overlay = segmap1.draw_on_image(images[0], draw_background=True)[0] image2_w_overlay = segmap2.draw_on_image(images[1], draw_background=True)[0] debug_image = iaa.draw_debug_image( images, segmentation_maps=[segmap1, segmap2]) assert self._image_contains(images[0, ...], debug_image) assert self._image_contains(images[1, ...], debug_image) assert self._image_contains(image1_w_overlay, debug_image) assert self._image_contains(image2_w_overlay, debug_image)