def test_boxfilter(self):
     """ Test boxfilter. """
     img = CImg(
         np.array([[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]]))
     img.boxfilter(2, 0, axis="y")
     img_expected = CImg(
         np.array([[0, 0.25, 0.25, 0], [0, 0.75, 0.75, 0],
                   [0, 0.75, 0.75, 0], [0, 0.25, 0.25, 0]]))
     self.assertTrue(np.allclose(img.asarray(), img_expected.asarray()))
 def test_vanvliet(self):
     """ Test vanvliet. """
     img = CImg(
         np.array([[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]]))
     img.vanvliet(1, cimg.FIRST_DERIV)
     img_expected = CImg(
         np.array([[0, 0, 0, 0], [0, 0.21424547, -0.09127644, -0.08401725],
                   [0, 0.21424547, -0.09127644, -0.08401725], [0, 0, 0,
                                                               0]]))
     self.assertTrue(np.allclose(img.asarray(), img_expected.asarray()))
 def test_blur(self):
     """ Test blur. """
     img = CImg(
         np.array([[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]]))
     img.blur(0.5)
     img_expected = CImg(
         np.array([[0.01423194, 0.10418227, 0.10418227, 0.01423194],
                   [0.10418227, 0.76264691, 0.76264691, 0.10418226],
                   [0.10418227, 0.76264691, 0.76264691, 0.10418226],
                   [0.01423194, 0.10418227, 0.10418227, 0.01423194]]))
     self.assertTrue(np.allclose(img.asarray(), img_expected.asarray()))
 def test_deriche(self):
     """ Test deriche. """
     img = CImg(
         np.array([[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]]))
     img.deriche(1)
     img_expected = CImg(
         np.array([[0, 0, 0, 0],
                   [0.26966834, 0.62711906, 0.62711906, 0.26966834],
                   [0.26966834, 0.62711906, 0.62711906, 0.26966834],
                   [0, 0, 0, 0]]))
     self.assertTrue(np.allclose(img.asarray(), img_expected.asarray()))
Esempio n. 5
0
 def test_fromarray(self):
     """ Test construction from array. """
     arr = np.ones((100, 50))
     im = CImg()
     im.fromarray(arr)
     self.assertTrue(np.allclose(arr, im.asarray().squeeze()))
     invalid_arr = np.ones((2, 3, 4, 5, 6))
     self.assertRaises(RuntimeError, im.fromarray, invalid_arr)
Esempio n. 6
0
 def test_draw_rectangle(self):
     """ Test draw rectangle."""
     img = CImg((5, 5))
     img.draw_rectangle(1, 1, 4, 4, 255)
     arr = np.array([[0, 0, 0, 0, 0], [0, 1, 1, 1, 1], [0, 1, 1, 1, 1],
                     [0, 1, 1, 1, 1], [0, 1, 1, 1, 1]]) * 255
     img_expected = CImg(arr)
     arr = img.asarray().squeeze()
     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)
Esempio n. 8
0
 def test_save_load(self):
     """ Test save/load half float. """
     im = CImg()
     arr = np.random.randn(3, 2, 500, 300)
     im.fromarray(arr)
     self.assertTrue(np.allclose(arr, im.asarray()))
     filename = self._get_testfilename() + '.cimg'
     im.save(filename)
     im2 = CImg()
     im2.load(filename)
     self.assertTrue(np.allclose(im2.asarray(), im.asarray()))
     os.remove(filename)
     # save/load half float
     filename = self._get_testfilename() + '.cimg'
     im.save_cimg_float16(filename)
     im3 = CImg()
     im3.load_cimg_float16(filename)
     self.assertTrue(np.allclose(im2.asarray(), im.asarray()))
     os.remove(filename)
Esempio n. 9
0
    def test_linear_atXY(self):
        ia = CImg((2, 2))
        # Create simple 2x2 checkerboard
        arr = ia.asarray()
        arr[0, 0, 0, 1] = 1
        arr[0, 0, 1, 1] = 1
        ia.resize(4, 4, interpolation_type=cimg.LINEAR)

        ib = CImg((2, 2))
        arr = ib.asarray()
        arr[0, 0, 0, 1] = 1
        arr[0, 0, 1, 1] = 1
        sc = (2 - 1) / (4 - 1)
        ic = CImg((4, 4))
        arr = ic.asarray()
        for x in range(ic.width):
            for y in range(ic.height):
                arr[0, 0, y, x] = ib.linear_atXY(sc * x, sc * y, 0, 0)

        self.assertTrue(np.allclose(ia.asarray(), ic.asarray()))
Esempio n. 10
0
 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)
Esempio n. 11
0
 def test_from_numpy(self):
     """ Test construction from numpy array. """
     arr = np.ones((100, 50))
     im = CImg(arr)
     self.assertTrue(np.allclose(arr, im.asarray().squeeze()))