From a1c1a80d3457f466ba9b84f1957cc0d99d4fd8be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Tue, 27 Aug 2013 01:19:18 +0200 Subject: [PATCH] Move FAST corner function to other corner functions --- skimage/feature/corner.py | 134 +++++++++++++++++++------------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/skimage/feature/corner.py b/skimage/feature/corner.py index 618bd2d9..e0133097 100644 --- a/skimage/feature/corner.py +++ b/skimage/feature/corner.py @@ -329,6 +329,73 @@ def corner_foerstner(image, sigma=1): return w, q +def corner_fast(image, n=12, threshold=0.15): + + """Extract FAST corners for a given image. + + Parameters + ---------- + image : 2D ndarray + Input image. + n : int + Minimum number of consecutive pixels out of 16 pixels on the circle + that should all be either brighter or darker w.r.t testpixel. + A point c on the circle is darker w.r.t test pixel p if + `Ic < Ip - threshold` and brighter if `Ic > Ip + threshold`. Also + stands for the n in `FAST-n` corner detector. + threshold : float + Threshold used in deciding whether the pixels on the circle are + brighter, darker or similar w.r.t. the test pixel. Decrease the + threshold when more corners are desired and vice-versa. + + Returns + ------- + response : ndarray + FAST corner response image. + + References + ---------- + .. [1] Edward Rosten and Tom Drummond + "Machine Learning for high-speed corner detection", + http://www.edwardrosten.com/work/rosten_2006_machine.pdf + .. [2] Wikipedia, "Features from accelerated segment test", + https://en.wikipedia.org/wiki/Features_from_accelerated_segment_test + + Examples + -------- + >>> from skimage.feature import corner_fast, corner_peaks + >>> square = np.zeros((12, 12)) + >>> square[3:9, 3:9] = 1 + >>> square + array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], + [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], + [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], + [ 0., 0., 0., 1., 1., 1., 1., 1., 1., 0., 0., 0.], + [ 0., 0., 0., 1., 1., 1., 1., 1., 1., 0., 0., 0.], + [ 0., 0., 0., 1., 1., 1., 1., 1., 1., 0., 0., 0.], + [ 0., 0., 0., 1., 1., 1., 1., 1., 1., 0., 0., 0.], + [ 0., 0., 0., 1., 1., 1., 1., 1., 1., 0., 0., 0.], + [ 0., 0., 0., 1., 1., 1., 1., 1., 1., 0., 0., 0.], + [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], + [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], + [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]]) + >>> corner_peaks(corner_fast(square, 9), min_distance=1) + array([[3, 3], + [3, 8], + [8, 3], + [8, 8]]) + + """ + image = np.squeeze(image) + if image.ndim != 2: + raise ValueError("Only 2-D gray-scale images supported.") + + image = img_as_float(image) + image = np.ascontiguousarray(image) + response = _corner_fast(image, n, threshold) + return response + + def corner_subpix(image, corners, window_size=11, alpha=0.99): """Determine subpixel position of corners. @@ -545,70 +612,3 @@ def corner_peaks(image, min_distance=10, threshold_abs=0, threshold_rel=0.1, return np.transpose(peaks.nonzero()) else: return peaks - - -def corner_fast(image, n=12, threshold=0.15): - - """Extract FAST corners for a given image. - - Parameters - ---------- - image : 2D ndarray - Input image. - n : int - Minimum number of consecutive pixels out of 16 pixels on the circle - that should all be either brighter or darker w.r.t testpixel. - A point c on the circle is darker w.r.t test pixel p if - `Ic < Ip - threshold` and brighter if `Ic > Ip + threshold`. Also - stands for the n in `FAST-n` corner detector. - threshold : float - Threshold used in deciding whether the pixels on the circle are - brighter, darker or similar w.r.t. the test pixel. Decrease the - threshold when more corners are desired and vice-versa. - - Returns - ------- - response : ndarray - FAST corner response image. - - References - ---------- - .. [1] Edward Rosten and Tom Drummond - "Machine Learning for high-speed corner detection", - http://www.edwardrosten.com/work/rosten_2006_machine.pdf - .. [2] Wikipedia, "Features from accelerated segment test", - https://en.wikipedia.org/wiki/Features_from_accelerated_segment_test - - Examples - -------- - >>> from skimage.feature import corner_fast, corner_peaks - >>> square = np.zeros((12, 12)) - >>> square[3:9, 3:9] = 1 - >>> square - array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], - [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], - [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], - [ 0., 0., 0., 1., 1., 1., 1., 1., 1., 0., 0., 0.], - [ 0., 0., 0., 1., 1., 1., 1., 1., 1., 0., 0., 0.], - [ 0., 0., 0., 1., 1., 1., 1., 1., 1., 0., 0., 0.], - [ 0., 0., 0., 1., 1., 1., 1., 1., 1., 0., 0., 0.], - [ 0., 0., 0., 1., 1., 1., 1., 1., 1., 0., 0., 0.], - [ 0., 0., 0., 1., 1., 1., 1., 1., 1., 0., 0., 0.], - [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], - [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], - [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]]) - >>> corner_peaks(corner_fast(square, 9), min_distance=1) - array([[3, 3], - [3, 8], - [8, 3], - [8, 8]]) - - """ - image = np.squeeze(image) - if image.ndim != 2: - raise ValueError("Only 2-D gray-scale images supported.") - - image = img_as_float(image) - image = np.ascontiguousarray(image) - response = _corner_fast(image, n, threshold) - return response