Exemplo n.º 1
0
 def test_03_02_adaptive_threshold_different(self):
     r = np.random.RandomState()
     r.seed(31)
     block = r.uniform(size=(10,10))
     i,j = np.mgrid[0:10:2,0:10:2]
     block[i,j] *= .5
     i,j = np.mgrid[0:50,0:50]
     img = block[i%10, j%10] * .5
     #
     # Make the middle higher in intensity
     #
     img[20:30, 20:30] *= 2
     global_threshold = T.get_global_threshold(T.TM_OTSU, block)
     adaptive_threshold = T.get_adaptive_threshold(
         T.TM_OTSU, img, global_threshold,
         adaptive_window_size = 10)
     #
     # Check that the gradients are positive for i,j<15 and negative
     # for i,j>=15
     #
     gradient = convolve1d(adaptive_threshold, [-1, 0, 1], 0)
     self.assertTrue(np.all(gradient[20:25, 20:30] < 0))
     self.assertTrue(np.all(gradient[25:30, 20:30] > 0))
     gradient = convolve1d(adaptive_threshold, [-1, 0, 1], 1)
     self.assertTrue(np.all(gradient[20:30, 20:25] < 0))
     self.assertTrue(np.all(gradient[20:30, 25:30] > 0))
Exemplo n.º 2
0
 def test_03_02_adaptive_threshold_different(self):
     r = np.random.RandomState()
     r.seed(31)
     block = r.uniform(size=(10,10))
     i,j = np.mgrid[0:10:2,0:10:2]
     block[i,j] *= .5
     i,j = np.mgrid[0:50,0:50]
     img = block[i%10, j%10] * .5
     #
     # Make the middle higher in intensity
     #
     img[20:30, 20:30] *= 2
     global_threshold = T.get_global_threshold(T.TM_OTSU, block)
     adaptive_threshold = T.get_adaptive_threshold(
         T.TM_OTSU, img, global_threshold,
         adaptive_window_size = 10)
     #
     # Check that the gradients are positive for i,j<15 and negative
     # for i,j>=15
     #
     gradient = convolve1d(adaptive_threshold, [-1, 0, 1], 0)
     self.assertTrue(np.all(gradient[20:25, 20:30] < 0))
     self.assertTrue(np.all(gradient[25:30, 20:30] > 0))
     gradient = convolve1d(adaptive_threshold, [-1, 0, 1], 1)
     self.assertTrue(np.all(gradient[20:30, 20:25] < 0))
     self.assertTrue(np.all(gradient[20:30, 25:30] > 0))
Exemplo n.º 3
0
 def test_03_01_adaptive_threshold_same(self):
     r = np.random.RandomState()
     r.seed(31)
     block = r.uniform(size=(10, 10))
     i, j = np.mgrid[0:10:2, 0:10:2]
     block[i, j] *= 0.5
     i, j = np.mgrid[0:50, 0:50]
     img = block[i % 10, j % 10]
     global_threshold = T.get_global_threshold(T.TM_OTSU, block)
     adaptive_threshold = T.get_adaptive_threshold(T.TM_OTSU, img, global_threshold, adaptive_window_size=10)
     np.testing.assert_almost_equal(adaptive_threshold, global_threshold)
Exemplo n.º 4
0
 def test_03_01_adaptive_threshold_same(self):
     r = np.random.RandomState()
     r.seed(31)
     block = r.uniform(size=(10,10))
     i,j = np.mgrid[0:10:2,0:10:2]
     block[i,j] *= .5
     i,j = np.mgrid[0:50,0:50]
     img = block[i%10, j%10]
     global_threshold = T.get_global_threshold(T.TM_OTSU, block)
     adaptive_threshold = T.get_adaptive_threshold(
         T.TM_OTSU, img, global_threshold,
         adaptive_window_size = 10)
     np.testing.assert_almost_equal(adaptive_threshold, global_threshold)