def test_05_02_otsu_entropy(self): '''Test the entropy version of Otsu''' np.random.seed(0) image = np.hstack((np.random.exponential(1.5, size=600), np.random.poisson(15, size=300))) image.shape = (30, 30) image = stretch(image) limage, d = T.log_transform(image) threshold = entropy(limage) threshold = T.inverse_log_transform(threshold, d) 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.use_weighted_variance.value = I.O_ENTROPY module.two_class_otsu.value = I.O_TWO_CLASS module.run(workspace) output = workspace.image_set.get_image(OUTPUT_IMAGE_NAME) self.assertTrue(np.all(output.pixel_data == expected))
def test_05_02_otsu_entropy(self): '''Test the entropy version of Otsu''' np.random.seed(0) image = np.hstack((np.random.exponential(1.5,size=600), np.random.poisson(15,size=300))) image.shape=(30,30) image = stretch(image) limage, d = T.log_transform(image) threshold = entropy(limage) threshold = T.inverse_log_transform(threshold, d) 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.use_weighted_variance.value = I.O_ENTROPY module.two_class_otsu.value = I.O_TWO_CLASS module.run(workspace) output = workspace.image_set.get_image(OUTPUT_IMAGE_NAME) self.assertTrue(np.all(output.pixel_data == expected))
def test_05_06_otsu3_entropy_high(self): '''Test the three-class otsu, entropy, middle = background''' np.random.seed(0) image = np.hstack((np.random.exponential(1.5, size=300), np.random.poisson(15, size=300), np.random.poisson(30, size=300))) image.shape = (30, 30) image = stretch(image) limage, d = T.log_transform(image) t1, t2 = entropy3(limage) threshold = T.inverse_log_transform(t1, d) 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.use_weighted_variance.value = I.O_ENTROPY module.two_class_otsu.value = I.O_THREE_CLASS module.assign_middle_to_foreground.value = I.O_FOREGROUND module.run(workspace) output = workspace.image_set.get_image(OUTPUT_IMAGE_NAME) self.assertTrue(np.all(output.pixel_data == expected))
def test_05_04_otsu3_wv_high(self): '''Test the three-class otsu, weighted variance middle = foreground''' np.random.seed(0) image = np.hstack((np.random.exponential(1.5, size=300), np.random.poisson(15, size=300), np.random.poisson(30, size=300))) image.shape = (30, 30) image = stretch(image) limage, d = T.log_transform(image) t1, t2 = otsu3(limage) threshold = T.inverse_log_transform(t1, d) 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.use_weighted_variance.value = I.O_WEIGHTED_VARIANCE module.two_class_otsu.value = I.O_THREE_CLASS module.assign_middle_to_foreground.value = I.O_FOREGROUND module.run(workspace) m = workspace.measurements m_threshold = m[cpmeas.IMAGE, I.FF_ORIG_THRESHOLD % module.get_measurement_objects_name()] self.assertAlmostEqual(m_threshold, threshold)
def test_05_06_otsu3_entropy_high(self): '''Test the three-class otsu, entropy, middle = background''' np.random.seed(0) image = np.hstack( (np.random.exponential(1.5, size=300), np.random.poisson(15, size=300), np.random.poisson(30, size=300))) image.shape = (30, 30) image = stretch(image) limage, d = T.log_transform(image) t1, t2 = entropy3(limage) threshold = T.inverse_log_transform(t1, d) 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.use_weighted_variance.value = I.O_ENTROPY module.two_class_otsu.value = I.O_THREE_CLASS module.assign_middle_to_foreground.value = I.O_FOREGROUND module.run(workspace) output = workspace.image_set.get_image(OUTPUT_IMAGE_NAME) self.assertTrue(np.all(output.pixel_data == expected))
def test_05_04_otsu3_wv_high(self): '''Test the three-class otsu, weighted variance middle = foreground''' np.random.seed(0) image = np.hstack((np.random.exponential(1.5,size=300), np.random.poisson(15,size=300), np.random.poisson(30,size=300))) image.shape=(30,30) image = stretch(image) limage, d = T.log_transform(image) t1,t2 = otsu3(limage) threshold = T.inverse_log_transform(t1, d) 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.use_weighted_variance.value = I.O_WEIGHTED_VARIANCE module.two_class_otsu.value = I.O_THREE_CLASS module.assign_middle_to_foreground.value = I.O_FOREGROUND module.run(workspace) m = workspace.measurements m_threshold = m[cpmeas.IMAGE, I.FF_ORIG_THRESHOLD % module.get_measurement_objects_name()] self.assertAlmostEqual(m_threshold, threshold)
def test_05_05_otsu3_entropy_low(self): '''Test the three-class otsu, entropy, middle = background''' np.random.seed(0) image = np.hstack((np.random.exponential(1.5, size=300), np.random.poisson(15, size=300), np.random.poisson(30, size=300))) image.shape = (30, 30) image = stretch(image) limage, d = T.log_transform(image) t1, t2 = entropy3(limage) threshold = T.inverse_log_transform(t2, d) 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.use_weighted_variance.value = I.O_ENTROPY module.two_class_otsu.value = I.O_THREE_CLASS module.assign_middle_to_foreground.value = I.O_BACKGROUND module.run(workspace) output = workspace.image_set.get_image(OUTPUT_IMAGE_NAME) m = workspace.measurements m_threshold = m[cpmeas.IMAGE, I.FF_ORIG_THRESHOLD % module.get_measurement_objects_name()] self.assertAlmostEqual(m_threshold, threshold)
def test_05_05_otsu3_entropy_low(self): '''Test the three-class otsu, entropy, middle = background''' np.random.seed(0) image = np.hstack((np.random.exponential(1.5,size=300), np.random.poisson(15,size=300), np.random.poisson(30,size=300))) image.shape=(30,30) image = stretch(image) limage, d = T.log_transform(image) t1,t2 = entropy3(limage) threshold = T.inverse_log_transform(t2, d) 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.use_weighted_variance.value = I.O_ENTROPY module.two_class_otsu.value = I.O_THREE_CLASS module.assign_middle_to_foreground.value = I.O_BACKGROUND module.run(workspace) output = workspace.image_set.get_image(OUTPUT_IMAGE_NAME) m = workspace.measurements m_threshold = m[cpmeas.IMAGE, I.FF_ORIG_THRESHOLD % module.get_measurement_objects_name()] self.assertAlmostEqual(m_threshold, threshold)