-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_Canny.py
78 lines (60 loc) · 2.52 KB
/
test_Canny.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from unittest import TestCase
import numpy as np
from Canny import Canny
__author__ = 'herman'
class Canny_identity10_1(TestCase):
'''
This case should have no edges due to the blur
'''
def setUp(self):
im = np.identity(10)
im = 1. * im
self.CannyInst = Canny(im)
class TestCannyI10_1(Canny_identity10_1):
def runTest(self):
self.assertEqual(self.CannyInst.grad.shape, (8, 8))
self.assertAlmostEqual(np.amax(self.CannyInst.grad), 0.0) # blur removes any edge from identity matrix
self.assertAlmostEqual(np.amin(self.CannyInst.grad), 0.0) # blur
self.assertEqual(self.CannyInst.segments.numpts, 0)
class Canny_identity10_100(TestCase):
def setUp(self):
im = np.eye(10, 10, 0)
for k in range(1, 10):
im += np.eye(10, 10, k)
im = 100. * im
self.CannyInst = Canny(im, sigma=0.0001)
class TestCannyI10_100(Canny_identity10_100):
def runTest(self):
self.assertEqual(self.CannyInst.grad.shape, (8, 8))
self.assertAlmostEqual(np.amax(self.CannyInst.grad), 0.0)
self.assertAlmostEqual(np.amin(self.CannyInst.grad), -1.0)
self.assertEqual(self.CannyInst.segments.numpts, 18) # 18 points
self.assertGreater(len(self.CannyInst.segments.segmentList),1)
class Canny_identity10_100_2(TestCase):
def setUp(self):
im = np.eye(10, 10, 0)
for k in range(1, 10):
im += np.eye(10, 10, -1 * k)
im = 100. * im
self.CannyInst = Canny(im, sigma=0.0001)
class TestCannyI10_100_2(Canny_identity10_100_2):
def runTest(self):
self.assertEqual(self.CannyInst.grad.shape, (8, 8))
self.assertAlmostEqual(np.amax(self.CannyInst.grad), 0.0)
self.assertAlmostEqual(np.amin(self.CannyInst.grad), -1.0)
self.assertEqual(self.CannyInst.segments.numpts, 18)
self.assertEqual(len(self.CannyInst.segments.segmentList), 1) # should have one segment
class Canny_eye20x20_mst(TestCase):
def setUp(self):
im = np.eye(20, 20, 0)
for k in range(1, 20):
im += np.eye(20, 20, -1 * k)
for k in range(18, 20):
im += np.eye(20, 20, k)
im = 100. * im
self.CannyInst = Canny(im, sigma=0.0001)
class TestCanny_eye_mst(Canny_eye20x20_mst):
def runTest(self):
self.assertEqual(self.CannyInst.grad.shape, (18, 18))
self.assertEqual(self.CannyInst.segments.numpts, 41) # must have at least two segments
self.assertEqual(len(self.CannyInst.segments.segmentList),2)