From 607d90cedfb322004955920f12bcaa6f0a510234 Mon Sep 17 00:00:00 2001 From: Ankit Agrawal Date: Sat, 7 Sep 2013 01:43:54 +0530 Subject: [PATCH] Minor optimizations; Renaming variables; Docstring corrections --- skimage/feature/corner_cy.pyx | 8 ++++---- skimage/feature/orb.py | 34 ++++++++++++++++++++-------------- skimage/feature/orb_cy.pyx | 11 ++++++----- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/skimage/feature/corner_cy.pyx b/skimage/feature/corner_cy.pyx index f4507b64..770b7e28 100644 --- a/skimage/feature/corner_cy.pyx +++ b/skimage/feature/corner_cy.pyx @@ -31,8 +31,8 @@ def corner_moravec(image, Py_ssize_t window_size=1): References ---------- - ..[1] http://kiwi.cs.dal.ca/~dparks/CornerDetection/moravec.htm - ..[2] http://en.wikipedia.org/wiki/Corner_detection + .. [1] http://kiwi.cs.dal.ca/~dparks/CornerDetection/moravec.htm + .. [2] http://en.wikipedia.org/wiki/Corner_detection Examples -------- @@ -193,10 +193,10 @@ def corner_orientations(image, Py_ssize_t[:, :] corners, mask): References ---------- - ..[1] Ethan Rublee, Vincent Rabaud, Kurt Konolige and Gary Bradski + .. [1] Ethan Rublee, Vincent Rabaud, Kurt Konolige and Gary Bradski "ORB : An efficient alternative to SIFT and SURF" http://www.vision.cs.chubu.ac.jp/CV-R/pdf/Rublee_iccv2011.pdf - ..[2] Paul L. Rosin, "Measuring Corner Properties" + .. [2] Paul L. Rosin, "Measuring Corner Properties" http://users.cs.cf.ac.uk/Paul.Rosin/corner2.pdf Examples diff --git a/skimage/feature/orb.py b/skimage/feature/orb.py index 736f7739..b5a6e706 100644 --- a/skimage/feature/orb.py +++ b/skimage/feature/orb.py @@ -13,7 +13,7 @@ from .orb_cy import _orb_loop def keypoints_orb(image, n_keypoints=200, fast_n=9, fast_threshold=0.20, harris_k=0.05, downscale=np.sqrt(2), n_scales=5): - """Compute Oriented Fast keypoints. + """Detect Oriented Fast keypoints. Parameters ---------- @@ -57,7 +57,7 @@ def keypoints_orb(image, n_keypoints=200, fast_n=9, fast_threshold=0.20, References ---------- - ..[1] Ethan Rublee, Vincent Rabaud, Kurt Konolige and Gary Bradski + .. [1] Ethan Rublee, Vincent Rabaud, Kurt Konolige and Gary Bradski "ORB : An efficient alternative to SIFT and SURF" http://www.vision.cs.chubu.ac.jp/CV-R/pdf/Rublee_iccv2011.pdf @@ -83,11 +83,14 @@ def keypoints_orb(image, n_keypoints=200, fast_n=9, fast_threshold=0.20, for i in range(n_scales): harris_response = corner_harris(pyramid[i], method='k', k=harris_k) - corners = corner_peaks(corner_fast(pyramid[i], fast_n, fast_threshold), min_distance=1) + corners = corner_peaks(corner_fast(pyramid[i], fast_n, fast_threshold), + min_distance=1) keypoints_list.append(corners) - orientations_list.append(corner_orientations(pyramid[i], corners, ofast_mask)) - scales_list.append(i * np.ones((corners.shape[0]), dtype=np.intp)) - harris_measure_list.append(harris_response[corners[:, 0], corners[:, 1]]) + orientations_list.append(corner_orientations(pyramid[i], corners, + ofast_mask)) + scales_list.append(i * np.ones(corners.shape[0], dtype=np.intp)) + harris_measure_list.append(harris_response[corners[:, 0], + corners[:, 1]]) keypoints = np.vstack(keypoints_list) orientations = np.hstack(orientations_list) @@ -98,7 +101,8 @@ def keypoints_orb(image, n_keypoints=200, fast_n=9, fast_threshold=0.20, return keypoints, orientations, scales else: best_indices = harris_measure.argsort()[::-1][:n_keypoints] - return keypoints[best_indices], orientations[best_indices], scales[best_indices] + return keypoints[best_indices], orientations[best_indices], \ + scales[best_indices] def descriptor_orb(image, keypoints, orientations, scales, @@ -134,7 +138,7 @@ def descriptor_orb(image, keypoints, orientations, scales, References ---------- - ..[1] Ethan Rublee, Vincent Rabaud, Kurt Konolige and Gary Bradski + .. [1] Ethan Rublee, Vincent Rabaud, Kurt Konolige and Gary Bradski "ORB : An efficient alternative to SIFT and SURF" http://www.vision.cs.chubu.ac.jp/CV-R/pdf/Rublee_iccv2011.pdf @@ -171,19 +175,21 @@ def descriptor_orb(image, keypoints, orientations, scales, curr_scale_mask = scales == k curr_scale_kpts = keypoints[curr_scale_mask] - curr_scale_kpts_orientation = orientations[curr_scale_mask] + curr_scale_orientation = orientations[curr_scale_mask] - border_mask = _mask_border_keypoints(curr_image, curr_scale_kpts, dist=13) + border_mask = _mask_border_keypoints(curr_image, curr_scale_kpts, + dist=13) curr_scale_kpts = curr_scale_kpts[border_mask] - curr_scale_kpts_orientation = curr_scale_kpts_orientation[border_mask] + curr_scale_orientation = curr_scale_orientation[border_mask] curr_scale_kpts = np.ascontiguousarray(curr_scale_kpts) - curr_scale_kpts_orientation = np.ascontiguousarray(curr_scale_kpts_orientation) - curr_scale_descriptors = _orb_loop(curr_image, curr_scale_kpts, curr_scale_kpts_orientation) + curr_scale_orientation = np.ascontiguousarray(curr_scale_orientation) + curr_scale_descriptors = _orb_loop(curr_image, curr_scale_kpts, + curr_scale_orientation) descriptors_list.append(curr_scale_descriptors) filtered_keypoints_list.append(curr_scale_kpts) - descriptors = np.vstack(descriptors_list).astype(np.bool) + descriptors = np.vstack(descriptors_list).view(np.bool) filtered_keypoints = np.vstack(filtered_keypoints_list) return descriptors, filtered_keypoints diff --git a/skimage/feature/orb_cy.pyx b/skimage/feature/orb_cy.pyx index 48c5d963..2a2018d8 100644 --- a/skimage/feature/orb_cy.pyx +++ b/skimage/feature/orb_cy.pyx @@ -17,7 +17,8 @@ def _orb_loop(double[:, ::1] image, Py_ssize_t[:, ::1] keypoints, cdef char[:, ::1] pos1 = binary_tests[:, 2:] cdef int[:, ::1] steered_pos0, steered_pos1 cdef double angle - cdef char[:, ::1] descriptors = np.zeros((keypoints.shape[0], 256), dtype=np.uint8) + cdef char[:, ::1] descriptors = np.zeros((keypoints.shape[0], 256), + dtype=np.uint8) for i in range(keypoints.shape[0]): angle = orientations[i] @@ -28,10 +29,10 @@ def _orb_loop(double[:, ::1] image, Py_ssize_t[:, ::1] keypoints, kc = keypoints[i, 1] for j in range(256): - pr0 = pos0[j][0] - pc0 = pos0[j][1] - pr1 = pos1[j][0] - pc1 = pos1[j][1] + pr0 = pos0[j, 0] + pc0 = pos0[j, 1] + pr1 = pos1[j, 0] + pc1 = pos1[j, 1] spr0 = round(sin_a * pr0 + cos_a * pc0) spc0 = round(cos_a * pr0 - sin_a * pc0)