Beispiel #1
0
 def test_one(self):
     shape = (128, 128, 128)
     points = tuple(np.array(s // 2) for s in shape)
     binary = synthetic.points_to_binary(points=points, shape=shape)
     self.assertEqual(binary.shape, shape)
     self.assertTrue(np.all(binary[points] == 255))
     self.assertTrue(np.all(binary[0, 0, 0] == 0))
Beispiel #2
0
 def test_random(self):
     n = 100
     shape = (128, 128, 128)
     points = synthetic.random_points(n=n, shape=shape)
     binary = synthetic.points_to_binary(points=points, shape=shape)
     self.assertEqual(binary.shape, shape)
     self.assertTrue(np.all(binary[points] == 255))
     self.assertTrue(binary.min() == 0)
Beispiel #3
0
def watershed_centers(image, centers, mask, **watershed_kwargs):
    seeds = points_to_binary(tuple(centers.T), image.shape, cval=1)
    markers = ndi.label(seeds)[0]
    labels = morphology.watershed(-image,
                                  markers,
                                  mask=mask,
                                  **watershed_kwargs)
    return labels
Beispiel #4
0
    def test_one(self):
        shape = (64, 64, 64)
        sigmas = [1, 2, 3, 4]
        offset = 1
        targets = [0.22313017, 0.68728930, 0.84648174, 0.91051036]

        points = tuple(np.array(s // 2) for s in shape)
        test_points = tuple(np.array(s // 2 + offset) for s in shape)
        binary = synthetic.points_to_binary(points=points, shape=shape)
        for sigma, target in zip(sigmas, targets):
            blobs = synthetic.binary_to_blobs(binary, sigma)
            self.assertEqual(blobs[points], 1)
            self.assertAlmostEqual(blobs[test_points], target)
Beispiel #5
0
    def test_random(self):
        n = 20
        shape = (128, 128, 128)
        sigmas = [1, 2, 3, 4]
        thresh = 0.7

        points = synthetic.random_points(n, shape)
        binary = synthetic.points_to_binary(points, shape)

        old_nb_foreground = 0
        for sigma in sigmas:
            blobs = synthetic.binary_to_blobs(binary, sigma)

            self.assertEqual(blobs.shape, shape)
            self.assertAlmostEqual(blobs.max(), 1)
            self.assertAlmostEqual(blobs.min(), 0)

            idx = np.where(blobs.ravel() > thresh)[0]
            new_nb_foreground = len(idx)
            self.assertTrue(old_nb_foreground < new_nb_foreground)
            old_nb_foreground = new_nb_foreground