Do not acquire GIL for corner detectors

This commit is contained in:
Johannes Schönberger
2015-05-20 07:45:04 -07:00
parent c52c7f4bfb
commit a489b85b22
2 changed files with 75 additions and 66 deletions
+8 -3
View File
@@ -5,7 +5,7 @@
import numpy as np import numpy as np
cimport numpy as cnp cimport numpy as cnp
from libc.float cimport DBL_MAX from libc.float cimport DBL_MAX
from libc.math cimport atan2 from libc.math cimport atan2, fabs
from ..util import img_as_float, pad from ..util import img_as_float, pad
from ..color import rgb2grey from ..color import rgb2grey
@@ -67,6 +67,8 @@ def corner_moravec(image, Py_ssize_t window_size=1):
cdef double msum, min_msum cdef double msum, min_msum
cdef Py_ssize_t r, c, br, bc, mr, mc, a, b cdef Py_ssize_t r, c, br, bc, mr, mc, a, b
with nogil:
for r in range(2 * window_size, rows - 2 * window_size): for r in range(2 * window_size, rows - 2 * window_size):
for c in range(2 * window_size, cols - 2 * window_size): for c in range(2 * window_size, cols - 2 * window_size):
min_msum = DBL_MAX min_msum = DBL_MAX
@@ -87,7 +89,8 @@ def corner_moravec(image, Py_ssize_t window_size=1):
cdef inline double _corner_fast_response(double curr_pixel, cdef inline double _corner_fast_response(double curr_pixel,
double* circle_intensities, double* circle_intensities,
signed char* bins, signed char state, char n): signed char* bins, signed char state,
char n) nogil:
cdef char consecutive_count = 0 cdef char consecutive_count = 0
cdef double curr_response cdef double curr_response
cdef Py_ssize_t l, m cdef Py_ssize_t l, m
@@ -97,7 +100,7 @@ cdef inline double _corner_fast_response(double curr_pixel,
if consecutive_count == n: if consecutive_count == n:
curr_response = 0 curr_response = 0
for m in range(16): for m in range(16):
curr_response += abs(circle_intensities[m] - curr_pixel) curr_response += fabs(circle_intensities[m] - curr_pixel)
return curr_response return curr_response
else: else:
consecutive_count = 0 consecutive_count = 0
@@ -124,6 +127,7 @@ def _corner_fast(double[:, ::1] image, signed char n, double threshold):
cdef double curr_response cdef double curr_response
with nogil:
for i in range(3, rows - 3): for i in range(3, rows - 3):
for j in range(3, cols - 3): for j in range(3, cols - 3):
@@ -254,6 +258,7 @@ def corner_orientations(image, Py_ssize_t[:, :] corners, mask):
cdef double curr_pixel cdef double curr_pixel
cdef double m01, m10, m01_tmp cdef double m01, m10, m01_tmp
with nogil:
for i in range(corners.shape[0]): for i in range(corners.shape[0]):
r0 = corners[i, 0] r0 = corners[i, 0]
c0 = corners[i, 1] c0 = corners[i, 1]
+4
View File
@@ -6,6 +6,7 @@ from skimage import data
from skimage import img_as_float from skimage import img_as_float
from skimage.color import rgb2gray from skimage.color import rgb2gray
from skimage.morphology import octagon from skimage.morphology import octagon
from skimage._shared.testing import test_parallel
from skimage.feature import (corner_moravec, corner_harris, corner_shi_tomasi, from skimage.feature import (corner_moravec, corner_harris, corner_shi_tomasi,
corner_subpix, peak_local_max, corner_peaks, corner_subpix, peak_local_max, corner_peaks,
@@ -99,6 +100,7 @@ def test_hessian_matrix_det():
assert_almost_equal(det, 0, decimal = 3) assert_almost_equal(det, 0, decimal = 3)
@test_parallel()
def test_square_image(): def test_square_image():
im = np.zeros((50, 50)).astype(float) im = np.zeros((50, 50)).astype(float)
im[:25, :25] = 1. im[:25, :25] = 1.
@@ -280,6 +282,7 @@ def test_corner_fast_image_unsupported_error():
assert_raises(ValueError, corner_fast, img) assert_raises(ValueError, corner_fast, img)
@test_parallel()
def test_corner_fast_lena(): def test_corner_fast_lena():
img = rgb2gray(data.astronaut()) img = rgb2gray(data.astronaut())
expected = np.array([[101, 198], expected = np.array([[101, 198],
@@ -335,6 +338,7 @@ def test_corner_orientations_even_shape_error():
np.asarray([[7, 7]]), np.ones((4, 4))) np.asarray([[7, 7]]), np.ones((4, 4)))
@test_parallel()
def test_corner_orientations_lena(): def test_corner_orientations_lena():
img = rgb2gray(data.lena()) img = rgb2gray(data.lena())
corners = corner_peaks(corner_fast(img, 11, 0.35)) corners = corner_peaks(corner_fast(img, 11, 0.35))