Added test for invalid quantile inputs

This commit is contained in:
Robin Wilson
2015-08-29 14:14:13 +01:00
parent 5f0665c99b
commit f9887e61e5
+34 -17
View File
@@ -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)