diff --git a/skimage/feature/tests/test_canny.py b/skimage/feature/tests/test_canny.py index 0bfb1fcf..17a147f3 100644 --- a/skimage/feature/tests/test_canny.py +++ b/skimage/feature/tests/test_canny.py @@ -70,26 +70,43 @@ class TestCanny(unittest.TestCase): result2 = F.canny(np.zeros((20, 20)), 4, 0, 0) self.assertTrue(np.all(result1 == result2)) + def test_quantile_threshold(self): + image = img_as_float(data.camera()[::50,::50]) -def test_quantile_threshold(): - image = img_as_float(data.camera()[::50,::50]) + # Correct output produced manually with quantiles + # of 0.8 and 0.6 for high and low respectively + correct_output = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0], + [0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0], + [0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0], + [0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0], + [0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0], + [0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0], + [0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=bool) - # Correct output produced manually with quantiles - # of 0.8 and 0.6 for high and low respectively - correct_output = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0], - [0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0], - [0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0], - [0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0], - [0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0], - [0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0], - [0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0], - [0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=bool) + result = F.canny(image, low_threshold=0.6, high_threshold=0.8, quantile_threshold=True) - result = F.canny(image, low_threshold=0.6, high_threshold=0.8, quantile_threshold=True) + assert_equal(result, correct_output) - assert_equal(result, correct_output) + def test_invalid_quantile_threshold(self): + image = img_as_float(data.camera()[::50,::50]) + with self.assertRaises(ValueError): + result = F.canny(image, quantile_threshold=True, + low_threshold=0.5, high_threshold=3.6) + + with self.assertRaises(ValueError): + result = F.canny(image, quantile_threshold=True, + low_threshold=99, high_threshold=0.9) + + with self.assertRaises(ValueError): + result = F.canny(image, quantile_threshold=True, + low_threshold=-5, high_threshold=0.5) + + with self.assertRaises(ValueError): + result = F.canny(image, quantile_threshold=True, + low_threshold=0.5, high_threshold=-100)