mirror of
https://github.com/wassname/scikit-image.git
synced 2026-06-29 20:35:40 +08:00
MAINT: avoid doing np.sum in the hot loop
(you gotta be kidding me, x2 speed-up)
This commit is contained in:
@@ -241,6 +241,18 @@ def is_surfacepoint(neighbors, points_LUT):
|
||||
return True
|
||||
|
||||
|
||||
@cython.boundscheck(False)
|
||||
@cython.wraparound(False)
|
||||
cdef inline bint is_endpoint(neighb_type neighbors):
|
||||
"""An endpoint has exactly one neighbor in the 26-neighborhood.
|
||||
"""
|
||||
# The center pixel is counted, thus r.h.s. is 2
|
||||
cdef int s = 0, j
|
||||
for j in range(27):
|
||||
s += neighbors[j]
|
||||
return s == 2
|
||||
|
||||
|
||||
@cython.boundscheck(False)
|
||||
@cython.wraparound(False)
|
||||
cdef bint is_Euler_invariant(neighb_type neighbors):
|
||||
@@ -612,14 +624,12 @@ cdef list _loop_through(img_type img,
|
||||
|
||||
get_neighborhood(img, p, r, c, neighborhood)
|
||||
|
||||
# check if (p, r, c) is an endpoint. An endpoint has exactly
|
||||
# one neighbor in the 26-neighborhood.
|
||||
# The center pixel is counted, thus r.h.s. is 2
|
||||
if np.sum(neighborhood) == 2:
|
||||
# check if (p, r, c) is an endpoint: endpoints are not deletable.
|
||||
if is_endpoint(neighborhood):
|
||||
continue
|
||||
|
||||
# check if point is Euler invariant (condition 1 in [Lee94])
|
||||
# if it is not, it's not deletable
|
||||
# check if point is Euler invariant (condition 1 in [Lee94]):
|
||||
# if it is not, it's not deletable.
|
||||
if not is_Euler_invariant(neighborhood):
|
||||
continue
|
||||
|
||||
|
||||
Reference in New Issue
Block a user