def test_draw_triangle(self): """ Test draw triangle. """ img = CImg((5, 5)) img.fill(0) img.draw_triangle(0, 0, 0, 4, 2, 2, 255) img_expected = CImg( np.array([[1, 0, 0, 0, 0], [1, 1, 0, 0, 0], [1, 1, 1, 0, 0], [1, 1, 0, 0, 0], [1, 0, 0, 0, 0]]) * 255) self.assertEqual(img, img_expected)
def test_invert_endianness(self): """ Test invert endianness. """ img = CImg((2, 2), dtype=cimg.uint16) img.fill(0xAAFF) img.invert_endianness() print(img.asarray()) img_expected = CImg((2, 2), dtype=cimg.uint16) img_expected.fill(0xFFAA) self.assertEqual(img, img_expected)
def test_norm(self): """ Test norm. """ img = CImg((10, 10, 1, 3)) arr = img.asarray() arr[0, :, :, :] = 0 arr[1, :, :, :] = 1 arr[2, :, :, :] = 2 img.norm(cimg.LINF_NORM) img_expected = CImg((10, 10, 1, 1)) img_expected.fill(2) self.assertEqual(img, img_expected)
def test_draw_polygon(self): """ Test draw polygon. """ img = CImg((5, 5), dtype=cimg.uint8) img.fill(0) points = np.array([(2, 0), (4, 2), (2, 4), (0, 2)]) img.draw_polygon(points, 255) # img.save('poly.png') arr = np.array([[0, 0, 1, 0, 0], [0, 1, 1, 1, 0], [1, 1, 1, 1, 1], [0, 1, 1, 1, 0], [0, 0, 1, 0, 0]]) * 255 img_expected = CImg(arr, dtype=cimg.uint8) # img_expected.save('poly2.png') self.assertEqual(img, img_expected)
def test_watershed(self): """ Test watershed. """ img = CImg( np.array([[0, 0.5, 1, 0.5], [1, 1, 0.5, 0], [0.5, 1, 0.5, 0], [1, 0.5, 0, 0]])) priority = CImg((4, 4)) priority.fill(1) img.watershed(priority) img_expected = CImg( np.array([[0.5, 0.5, 1, 0.5], [1, 1, 0.5, 0.5], [0.5, 1, 0.5, 0.5], [1, 0.5, 0.5, 0.5]])) self.assertEqual(img, img_expected)
def test_fill(self): """ Test fill. """ img = CImg((2, 2)) img.fill(42) img_expected = CImg(np.ones((2, 2)) * 42) self.assertEqual(img, img_expected)