From 4406c0f0b43a47cc9a37d65dee3a90bf4cfe06e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 1 Dec 2013 11:31:40 +0100 Subject: [PATCH] Speedup corner orientations --- skimage/feature/corner_cy.pyx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/skimage/feature/corner_cy.pyx b/skimage/feature/corner_cy.pyx index 3fd860a2..86ad3c43 100644 --- a/skimage/feature/corner_cy.pyx +++ b/skimage/feature/corner_cy.pyx @@ -240,7 +240,8 @@ def corner_orientations(image, Py_ssize_t[:, :] corners, mask): if mask.shape[0] % 2 != 1 or mask.shape[1] % 2 != 1: raise ValueError("Size of mask must be uneven.") - cdef char[:, ::1] cmask = np.ascontiguousarray(mask != 0, dtype=np.uint8) + cdef unsigned char[:, ::1] cmask = np.ascontiguousarray(mask != 0, + dtype=np.uint8) cdef Py_ssize_t i, r, c, r0, c0 cdef Py_ssize_t mrows = mask.shape[0] @@ -251,7 +252,7 @@ def corner_orientations(image, Py_ssize_t[:, :] corners, mask): constant_values=0) cdef double[:] orientations = np.zeros(corners.shape[0], dtype=np.double) cdef double curr_pixel - cdef double m01, m10 + cdef double m01, m10, m01_tmp for i in range(corners.shape[0]): r0 = corners[i, 0] @@ -261,11 +262,13 @@ def corner_orientations(image, Py_ssize_t[:, :] corners, mask): m10 = 0 for r in range(mrows): + m01_tmp = 0 for c in range(mcols): if cmask[r, c]: curr_pixel = cimage[r0 + r, c0 + c] m10 += curr_pixel * (c - mcols2) - m01 += curr_pixel * (r - mrows2) + m01_tmp += curr_pixel + m01 += m01_tmp * (r - mrows2) orientations[i] = atan2(m01, m10)