From 5161687730be0222ae9448697bd9a11dc6ef999b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Sat, 16 Feb 2013 08:11:30 +0100 Subject: [PATCH] various minor fixes --- skimage/transform/_hough_transform.pyx | 61 ++++++++------------------ skimage/transform/hough_transform.py | 7 +-- 2 files changed, 20 insertions(+), 48 deletions(-) diff --git a/skimage/transform/_hough_transform.pyx b/skimage/transform/_hough_transform.pyx index 3c39d815..c274ed0d 100644 --- a/skimage/transform/_hough_transform.pyx +++ b/skimage/transform/_hough_transform.pyx @@ -22,55 +22,30 @@ cdef inline Py_ssize_t round(double r): def _hough_circle(np.ndarray img, \ np.ndarray[ndim=1, dtype=np.npy_intp] radius, \ normalize=True): + """Perform a circular Hough transform. + Parameters + ---------- + img : (M, N) ndarray + Input image with nonzero values representing edges. + radius : ndarray + Radii at which to compute the Hough transform. + normalize : boolean, optional + Normalize the accumulator with the number + of pixels used to draw the radius + + Returns + ------- + H : 3D ndarray (radius index, (M, N) ndarray) + Hough transform accumulator for each radius + + """ if img.ndim != 2: raise ValueError('The input image must be 2D.') # compute the nonzero indexes cdef np.ndarray[ndim=1, dtype=np.npy_intp] x, y - y, x = np.PyArray_Nonzero(img) - - # Offset the image - max_radius = radius.max() - x = x + max_radius - y = y + max_radius - - cdef list H = list() - - for rad in radius: - # Accumulator - out = np.zeros((img.shape[0] + 2 * max_radius, img.shape[1] + 2 * max_radius)) - - # Store in memory the circle of given radius - # centered at (0,0) - circle_x, circle_y = circle_perimeter(0, 0, rad) - - # For each non zero pixel - for (px, py) in zip(x, y): - # Plug the circle at (px, py), - # its coordinates are (tx, ty) - tx = circle_x + px - ty = circle_y + py - out[tx, ty] += 1 - - if normalize: - out = out / len(circle_x) - - H.append(out) - return np.array(H) - - -@cython.boundscheck(False) -def _hough_circle(np.ndarray img, \ - np.ndarray[ndim=1, dtype=np.npy_intp] radius, \ - normalize=True): - - if img.ndim != 2: - raise ValueError('The input image must be 2D.') - - # compute the nonzero indexes - cdef np.ndarray[ndim=1, dtype=np.npy_intp] x, y - y, x = np.PyArray_Nonzero(img) + y, x = np.nonzero(img) # Offset the image max_radius = radius.max() diff --git a/skimage/transform/hough_transform.py b/skimage/transform/hough_transform.py index 88ef4b83..17b76826 100644 --- a/skimage/transform/hough_transform.py +++ b/skimage/transform/hough_transform.py @@ -146,7 +146,7 @@ def hough_line(img, theta=None): return _hough(img, theta) def hough_circle(img, radius, normalize=True): - """Perform a circle Hough transform. + """Perform a circular Hough transform. Parameters ---------- @@ -154,7 +154,7 @@ def hough_circle(img, radius, normalize=True): Input image with nonzero values representing edges. radius : ndarray Radii at which to compute the Hough transform. - normalize : boolean + normalize : boolean, optional Normalize the accumulator with the number of pixels used to draw the radius @@ -163,9 +163,6 @@ def hough_circle(img, radius, normalize=True): H : 3D ndarray (radius index, (M, N) ndarray) Hough transform accumulator for each radius - Examples - -------- - """ return _hough_circle(img, radius, normalize)