コード例 #1
0
ファイル: test_filter.py プロジェクト: cagridz/centrosome
 def test_03_02_all_masked(self):
     # Regression test of 1286 - exception if totally masked image
     #
     i = np.linspace(-1, 1, 11)**2
     i, j = i[:, np.newaxis], i[np.newaxis, :]
     image = np.sqrt(i * i + j * j)
     mask = np.zeros(image.shape, bool)
     F.convex_hull_transform(image, levels=8, mask=mask)
コード例 #2
0
ファイル: test_filter.py プロジェクト: cagridz/centrosome
 def test_01_05_concave(self):
     '''The convex hull transform of a concave figure is the convex hull'''
     expected = np.zeros((10, 20))
     expected[2:8, 7:14] = 1
     image = expected.copy()
     image[4:6, 7:10] = .5
     self.assertTrue(np.all(F.convex_hull_transform(image) == expected))
コード例 #3
0
ファイル: test_filter.py プロジェクト: cagridz/centrosome
 def test_04_02_two_pass(self):
     '''Test the two-pass at multiple levels chunk looping'''
     np.random.seed(42)
     #
     # Make an image that monotonically decreases from the center
     #
     i, j = np.mgrid[-50:51, -50:51].astype(float) / 100.
     image = 1 - np.sqrt(i**2 + j**2)
     #
     # Riddle it with holes
     #
     holes = np.random.uniform(size=image.shape) < .01
     image[holes] = 0
     result = F.convex_hull_transform(image,
                                      levels=256,
                                      chunksize=1000,
                                      pass_cutoff=256)
     expected = F.convex_hull_transform(image, pass_cutoff=256)
     np.testing.assert_equal(result, expected)
コード例 #4
0
ファイル: test_filter.py プロジェクト: cagridz/centrosome
    def test_02_01_two_levels(self):
        '''Test operation on two grayscale levels'''

        expected = np.zeros((20, 30))
        expected[3:18, 3:27] = .5
        expected[8:15, 10:20] = 1
        image = expected.copy()
        image[:, 15] = 0
        image[10, :] = 0
        # need an odd # of bins in order to have .5 be a bin
        self.assertTrue(np.all(F.convex_hull_transform(image, 7) == expected))
コード例 #5
0
ファイル: test_filter.py プロジェクト: cagridz/centrosome
 def test_04_01_many_chunks(self):
     '''Test the two-pass at a single level chunk looping'''
     np.random.seed(41)
     #
     # Make an image that monotonically decreases from the center
     #
     i, j = np.mgrid[-50:51, -50:51].astype(float) / 100.
     image = 1 - np.sqrt(i**2 + j**2)
     expected = image.copy()
     #
     # Riddle it with holes
     #
     holes = np.random.uniform(size=image.shape) < .01
     image[holes] = 0
     result = F.convex_hull_transform(image,
                                      levels=256,
                                      chunksize=1000,
                                      pass_cutoff=256)
     diff = np.abs(result - expected)
     self.assertTrue(np.sum(diff > 1 / 256.) <= np.sum(holes))
     expected = F.convex_hull_transform(image, pass_cutoff=256)
     np.testing.assert_equal(result, expected)
コード例 #6
0
ファイル: test_filter.py プロジェクト: cagridz/centrosome
    def test_03_01_masked(self):
        '''Test operation on a masked image'''

        expected = np.zeros((20, 30))
        expected[3:18, 3:27] = .5
        expected[8:15, 10:20] = 1
        image = expected.copy()
        image[:, 15] = 0
        image[10, :] = 0
        mask = np.ones((20, 30), bool)
        mask[:, 0] = False
        image[:, 0] = .75

        result = F.convex_hull_transform(image, levels=7, mask=mask)
        self.assertTrue(np.all(result == expected))
コード例 #7
0
ファイル: test_filter.py プロジェクト: cagridz/centrosome
    def test_01_04_convex(self):
        '''The convex hull transform of a convex figure is itself'''

        image = np.zeros((10, 20))
        image[2:7, 7:14] = 1
        self.assertTrue(np.all(F.convex_hull_transform(image) == image))
コード例 #8
0
ファイル: test_filter.py プロジェクト: cagridz/centrosome
 def test_01_03_line(self):
     '''The convex hull transform of a line of foreground pixels is itself'''
     image = np.zeros((10, 20))
     image[5, 7:14] = 1
     self.assertTrue(np.all(F.convex_hull_transform(image) == image))
コード例 #9
0
ファイル: test_filter.py プロジェクト: cagridz/centrosome
 def test_01_02_point(self):
     '''The convex hull transform of 1 foreground pixel is itself'''
     image = np.zeros((10, 20))
     image[5, 10] = 1
     self.assertTrue(np.all(F.convex_hull_transform(image) == image))
コード例 #10
0
ファイル: test_filter.py プロジェクト: cagridz/centrosome
 def test_01_01_zeros(self):
     '''The convex hull transform of an array of identical values is itself'''
     self.assertTrue(
         np.all(F.convex_hull_transform(np.zeros((10, 20))) == 0))