Example #1
0
 def test_01_01_negative_log_otsu(self):
     '''regression test of img-1466'''
     
     r = np.random.RandomState()
     r.seed(11)
     img = r.uniform(size=(10,10))
     img[0,0] = -1
     unmasked = T.get_otsu_threshold(img)
     masked = T.get_otsu_threshold(img, img >= 0)
     self.assertEqual(unmasked, masked)
Example #2
0
 def test_01_01_negative_log_otsu(self):
     '''regression test of img-1466'''
     
     r = np.random.RandomState()
     r.seed(11)
     img = r.uniform(size=(10,10))
     img[0,0] = -1
     unmasked = T.get_otsu_threshold(img)
     masked = T.get_otsu_threshold(img, img >= 0)
     self.assertEqual(unmasked, masked)
 def test_04_06_per_object(self):
     '''Test that per-object thresholding works'''
     np.random.seed(0)
     image = np.random.uniform(size=(20,20)) * .5
     labels = np.ones((20,20),int)
     labels[10:,:] *= 2
     image[labels==2] *= 2
     expected=image > T.get_otsu_threshold(image[labels==1])
     expected[labels==2] = image[labels==2] > T.get_otsu_threshold(image[labels==2])
     workspace, module = self.make_workspace(image)
     objects = cpo.Objects()
     objects.segmented = labels
     workspace.object_set.add_objects(objects,"HelloKitty")
     module.binary.value = A.BINARY
     module.threshold_method.value = T.TM_OTSU_PER_OBJECT
     module.enclosing_objects_name.value = "HelloKitty"
     module.run(workspace)
     output = workspace.image_set.get_image(OUTPUT_IMAGE_NAME)
     self.assertTrue(np.all(output.pixel_data == expected))
Example #4
0
 def test_04_06_per_object(self):
     '''Test that per-object thresholding works'''
     np.random.seed(0)
     image = np.random.uniform(size=(20,20)) * .5
     labels = np.ones((20,20),int)
     labels[10:,:] *= 2
     image[labels==2] *= 2
     expected=image > T.get_otsu_threshold(image[labels==1])
     expected[labels==2] = image[labels==2] > T.get_otsu_threshold(image[labels==2])
     workspace, module = self.make_workspace(image)
     objects = cpo.Objects()
     objects.segmented = labels
     workspace.object_set.add_objects(objects,"HelloKitty")
     module.binary.value = A.BINARY
     module.threshold_method.value = T.TM_OTSU_PER_OBJECT
     module.enclosing_objects_name.value = "HelloKitty"
     module.run(workspace)
     output = workspace.image_set.get_image(OUTPUT_IMAGE_NAME)
     self.assertTrue(np.all(output.pixel_data == expected))
 def test_04_02_binary_global(self):
     '''Test a binary threshold with Otsu global method'''
     np.random.seed(0)
     image = np.random.uniform(size=(20,20))
     threshold = T.get_otsu_threshold(image)
     expected = image > threshold
     workspace, module = self.make_workspace(image)
     module.binary.value = A.BINARY
     module.threshold_method.value = T.TM_OTSU_GLOBAL
     module.run(workspace)
     output = workspace.image_set.get_image(OUTPUT_IMAGE_NAME)
     self.assertTrue(np.all(output.pixel_data == expected))
Example #6
0
 def test_04_02_binary_global(self):
     '''Test a binary threshold with Otsu global method'''
     np.random.seed(0)
     image = np.random.uniform(size=(20, 20))
     threshold = T.get_otsu_threshold(image)
     expected = image > threshold
     workspace, module = self.make_workspace(image)
     module.binary.value = A.BINARY
     module.threshold_method.value = T.TM_OTSU_GLOBAL
     module.run(workspace)
     output = workspace.image_set.get_image(OUTPUT_IMAGE_NAME)
     self.assertTrue(np.all(output.pixel_data == expected))
 def test_04_03_binary_correction(self):
     '''Test a binary threshold with a correction factor'''
     np.random.seed(0)
     image = np.random.uniform(size=(20, 20))
     threshold = T.get_otsu_threshold(image) * .5
     expected = image > threshold
     workspace, module = self.make_workspace(image)
     module.binary.value = A.BINARY
     module.threshold_scope.value = I.TS_GLOBAL
     module.threshold_method.value = T.TM_OTSU
     module.threshold_correction_factor.value = .5
     module.run(workspace)
     output = workspace.image_set.get_image(OUTPUT_IMAGE_NAME)
     self.assertTrue(np.all(output.pixel_data == expected))
 def test_04_03_binary_correction(self):
     '''Test a binary threshold with a correction factor'''
     np.random.seed(0)
     image = np.random.uniform(size=(20,20))
     threshold = T.get_otsu_threshold(image) *.5
     expected = image > threshold
     workspace, module = self.make_workspace(image)
     module.binary.value = A.BINARY
     module.threshold_scope.value = I.TS_GLOBAL
     module.threshold_method.value = T.TM_OTSU
     module.threshold_correction_factor.value = .5
     module.run(workspace)
     output = workspace.image_set.get_image(OUTPUT_IMAGE_NAME)
     self.assertTrue(np.all(output.pixel_data == expected))
Example #9
0
 def test_01_00_nothing(self):
     result = T.get_otsu_threshold(-np.ones((10,10)))
Example #10
0
 def test_01_00_nothing(self):
     result = T.get_otsu_threshold(-np.ones((10,10)))