From e5ddf8590743b67fcafa273a68e59b830c4dca7e Mon Sep 17 00:00:00 2001 From: Pieter Holtzhausen Date: Sat, 20 Aug 2011 11:15:50 +0200 Subject: [PATCH] Debugging similar angles --- scikits/image/transform/_hough_transform.pyx | 27 ++++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/scikits/image/transform/_hough_transform.pyx b/scikits/image/transform/_hough_transform.pyx index d1737f30..5d0d8b92 100644 --- a/scikits/image/transform/_hough_transform.pyx +++ b/scikits/image/transform/_hough_transform.pyx @@ -77,8 +77,7 @@ def _probabilistic_hough(np.ndarray img, int value_threshold, int line_length, \ # calculate thetas if none specified if theta is None: theta = np.linspace(math.pi/2, -math.pi/2, 180) - p_2 = math.pi/2 - theta = p_2-np.arange(180)/180.0*p_2*2 + theta = math.pi/2-np.arange(180)/180.0* math.pi ctheta = np.cos(theta) stheta = np.sin(theta) cdef int height = img.shape[0] @@ -113,6 +112,7 @@ def _probabilistic_hough(np.ndarray img, int value_threshold, int line_length, \ for i in range(num_indexes): mask[y_idxs[i], x_idxs[i]] = 1 settle = 0 + print while 1: # select random non-zero point count = len(points) @@ -125,6 +125,7 @@ def _probabilistic_hough(np.ndarray img, int value_threshold, int line_length, \ # if previously eliminated, skip if not mask[y, x]: continue + print "select", y, x value = 0 max_value = value_threshold-1 max_theta = -1 @@ -135,18 +136,22 @@ def _probabilistic_hough(np.ndarray img, int value_threshold, int line_length, \ accum[accum_idx, j] += 1 value = accum[accum_idx, j] if value > max_value: + print "max", j, value max_value = value max_theta = j - # if two max angles are very similar, extend the threshold for a while - if j != max_theta and value == max_value and abs(j - max_theta) == 1: - settle += 1 - if settle > 100: - other_max = 0 - else: - other_max = 1 + # if two bordering angles have max values, extend the threshold for a while + if j != max_theta and value == max_value: + if abs(j - max_theta) <= 2: + if settle > 100: + other_max = 0 + else: + other_max = 1 + if j == 134 or j == 135: + print j, value, accum_idx, ctheta[j], stheta[j] if max_value < value_threshold or other_max: continue settle = 0 + print "THETA", max_theta, max_value # from the random point walk in opposite directions and find line beginning and end a = -stheta[max_theta] b = ctheta[max_theta] @@ -160,14 +165,14 @@ def _probabilistic_hough(np.ndarray img, int value_threshold, int line_length, \ else: dx0 = -1 dy0 = round(b * (1 << shift) / fabs(a)) - y0 = (y0 << shift) #+ (1 << (shift - 1)) + y0 = (y0 << shift) + (1 << (shift - 1)) else: if b > 0: dy0 = 1 else: dy0 = -1 dx0 = round(a * (1 << shift) / fabs(b)) - x0 = (x0 << shift) #+ (1 << (shift - 1)) + x0 = (x0 << shift) + (1 << (shift - 1)) # pass 1: walk the line, merging lines less than specified gap length for k in range(2):