mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-27 11:27:08 +08:00
various minor fixes
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user