various minor fixes

This commit is contained in:
François Boulogne
2013-02-25 22:56:27 +01:00
parent 88eaaad9c7
commit 5161687730
2 changed files with 20 additions and 48 deletions
+18 -43
View File
@@ -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()
+2 -5
View File
@@ -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)