Exemplo n.º 1
0
 def test_div(self):
     """ Test div. """
     x = np.ones((5, 4)) * 2
     y = np.ones((5, 4)) * 3
     img_x = CImg(x)
     img_y = CImg(y)
     img_x.div(img_y)
     img_expected = CImg(x / y)
     self.assertEqual(img_x, img_expected)
Exemplo n.º 2
0
 def test_mul(self):
     """ Test mul. """
     x = np.ones((5, 4)) * 2
     y = np.ones((5, 4)) * 3
     img_x = CImg(x)
     img_y = CImg(y)
     img_x.mul(img_y)
     img_expected = CImg(x * y)
     self.assertEqual(img_x, img_expected)
Exemplo n.º 3
0
 def test_save_tiff(self):
     """ Test save tiff. """
     img = CImg((100, 100), dtype=cimg.uint8)
     img.rand(0, 255)
     filename = self._get_testfilename() + '.tiff'
     img.save_tiff(filename,
                   compression_type=cimg.C_LZW,
                   voxel_size=0,
                   description="Test tiff")
     self.assertTrue(os.path.isfile(filename))
     os.remove(filename)
Exemplo n.º 4
0
 def test_round(self):
     """ Test round. """
     img = CImg(np.array([2.3, -1.7, 1.5, -0.1]))
     img.round()
     img_expected = CImg(np.array([2, -2, 2, 0]))
     self.assertEqual(img, img_expected)
Exemplo n.º 5
0
 def test_noise(self):
     """ Test noise. """
     img = CImg(np.zeros((5, 5)))
     img.noise(2)
     img_not_expected = CImg(np.zeros((5, 5)))
     self.assertNotEqual(img, img_not_expected)
Exemplo n.º 6
0
 def test_tan(self):
     arr = np.linspace(-0.5, 0.5, 100)
     img = CImg(arr)
     self.assertTrue(np.allclose(np.tan(arr), img.tan().asarray()))
Exemplo n.º 7
0
 def test_sinc(self):
     arr = np.linspace(-10, 10, 100)
     img = CImg(arr)
     self.assertTrue(np.allclose(np.sinc(arr / np.pi),
                                 img.sinc().asarray()))
Exemplo n.º 8
0
 def test_equalize(self):
     """ Test equalize. """
     img = CImg(np.array([1, 1, 2, 2]))
     img.equalize(2, 1, 2)
     img_expected = CImg(np.array([1.5, 1.5, 2, 2]))
     self.assertEqual(img, img_expected)
Exemplo n.º 9
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()))
Exemplo n.º 10
0
 def test_load_jpeg(self):
     """ Test loading a JPEG file. """
     img = CImg()
     img.load_jpeg(get_test_image('jpg'))
     self._check_image_dimensions(img)
Exemplo n.º 11
0
 def test_threshold(self):
     """ Test threshold. """
     img = CImg(np.array([0, 1, 2, 3, 4]))
     img.threshold(2)
     img_expected = CImg(np.array([0, 0, 1, 1, 1]))
     self.assertEqual(img, img_expected)
Exemplo n.º 12
0
 def test_load(self):
     """ Test load. """
     img = CImg()
     self.assertRaises(RuntimeError, img.load, 'notexistent.jpg')
     img.load(get_test_image())
     self._check_image_dimensions(img)
Exemplo n.º 13
0
 def test_load_bmp(self):
     """ Test loading a BMP file. """
     img = CImg()
     img.load_bmp(get_test_image('bmp'))
     self._check_image_dimensions(img)
Exemplo n.º 14
0
 def test_atan(self):
     arr = np.random.randn(10, 5)
     img = CImg(arr)
     self.assertTrue(np.allclose(np.arctan(arr), img.atan().asarray()))
Exemplo n.º 15
0
 def test_acos(self):
     arr = -np.ones((10, 5))
     img = CImg(arr)
     self.assertTrue(np.allclose(np.arccos(arr), img.acos().asarray()))
Exemplo n.º 16
0
 def test_tanh(self):
     arr = np.random.randn(10, 5)
     img = CImg(arr)
     self.assertTrue(np.allclose(np.tanh(arr), img.tanh().asarray()))
Exemplo n.º 17
0
 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)
Exemplo n.º 18
0
 def test_load_png(self):
     """ Test loading a PNG file. """
     img = CImg()
     img.load_png(get_test_image('png'))
     self._check_image_dimensions(img)
Exemplo n.º 19
0
 def test_quantize(self):
     """ Test quantize. """
     img = CImg(np.array([0, 1, 2, 3, 4]))
     img.quantize(2, keep_range=True)
     img_expected = CImg(np.array([0, 0, 2, 2, 2]))
     self.assertEqual(img, img_expected)
Exemplo n.º 20
0
 def test_load_tiff(self):
     """ Test loading a TIFF file. """
     img = CImg()
     img.load_tiff(get_test_image('tiff'))
     self._check_image_dimensions(img)
Exemplo n.º 21
0
 def test_histogram(self):
     """ Test histogram. """
     img = CImg(np.array([0, 1, 2, 3, 4]))
     img.histogram(2, 0, 4)
     img_expected = CImg(np.array([2, 3]))
     self.assertEqual(img, img_expected)
Exemplo n.º 22
0
 def test_noarg(self):
     """ Test construction of empty image. """
     im = CImg()
     self.assertEqual(im.shape, (0, 0, 0, 0))
Exemplo n.º 23
0
 def test_from_file(self):
     """ Test construction from file. """
     im = CImg(get_test_image())
     self.assertEqual(im.shape, (3, 1, 797, 1200))
Exemplo n.º 24
0
 def test_dot(self):
     """ Test dot. """
     img1 = CImg(np.array([[2, -5], [0, 3]]))
     img2 = CImg(np.array([[2, -3], [0, 3]]))
     self.assertEqual(img1.dot(img2), 28)
Exemplo n.º 25
0
 def test_size(self):
     """ Test construction with size tuple. """
     im = CImg((100, 50))
     self.assertEqual(im.shape, (1, 1, 50, 100))
     im = CImg((100))
     self.assertEqual(im.shape, (1, 1, 1, 100))
Exemplo n.º 26
0
 def test_sqr(self):
     arr = np.random.randn(10, 5)
     img = CImg(arr)
     self.assertTrue(np.allclose(arr * arr, img.sqr().asarray()))
Exemplo n.º 27
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()))
Exemplo n.º 28
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)
Exemplo n.º 29
0
 def test_magnitude(self):
     """ Test magnitude. """
     img = CImg(np.array([[2, -5], [0, 3]]))
     self.assertEqual(img.magnitude(cimg.L1_NORM), 10)
Exemplo n.º 30
0
 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)