From e26dc02ead617887b6a6c29011e7d0d4a95374b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Tue, 11 Sep 2012 19:20:28 +0200 Subject: [PATCH] Add Kitchen and Rosenfeld corner detector --- skimage/feature/__init__.py | 2 +- skimage/feature/corner.py | 59 +++++++++++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/skimage/feature/__init__.py b/skimage/feature/__init__.py index 5b421c9c..f74f31a8 100644 --- a/skimage/feature/__init__.py +++ b/skimage/feature/__init__.py @@ -1,6 +1,6 @@ from ._hog import hog from .texture import greycomatrix, greycoprops, local_binary_pattern from .peak import peak_local_max -from .corner import corner_harris, corner_shi_tomasi +from .corner import corner_kitchen_rosenfeld, corner_harris, corner_shi_tomasi from .corner_cy import corner_moravec from .template import match_template diff --git a/skimage/feature/corner.py b/skimage/feature/corner.py index e8f6aa2a..9ebee9f2 100644 --- a/skimage/feature/corner.py +++ b/skimage/feature/corner.py @@ -4,6 +4,30 @@ from skimage.color import rgb2grey from . import peak +def _compute_derivatives(image): + """Compute derivatives in x and y direction. + + Parameters + ---------- + image : ndarray + Input image. + + Returns + ------- + imx, imy : arrays + Derivatives in x and y direction. + + """ + + gradient_weights = np.array([-1, 0, 1]) + imx = ndimage.convolve1d(image, gradient_weights, axis=0, + mode='constant', cval=0) + imy = ndimage.convolve1d(image, gradient_weights, axis=1, + mode='constant', cval=0) + + return imx, imy + + def _compute_auto_correlation(image, sigma): """Compute auto-correlation matrix using sum of squared differences. @@ -25,12 +49,7 @@ def _compute_auto_correlation(image, sigma): if image.ndim == 3: image = rgb2grey(image) - # derivatives - gradient_weights = np.array([-1, 0, 1]) - imx = ndimage.convolve1d(image, gradient_weights, axis=0, - mode='constant', cval=0) - imy = ndimage.convolve1d(image, gradient_weights, axis=1, - mode='constant', cval=0) + imx, imy = _compute_derivatives(image) # structure tensore Axx = ndimage.gaussian_filter(imx * imx, sigma, mode='constant', cval=0) @@ -40,6 +59,34 @@ def _compute_auto_correlation(image, sigma): return Axx, Axy, Ayy +def corner_kitchen_rosenfeld(image): + """Compute Kitchen and Rosenfeld response image. + + This corner detector uses information in the auto-correlation matrix + (sum of squared differences) to make assumptions about the type of point. + + Parameters + ---------- + image : ndarray + Input image. + + Returns + ------- + response : ndarray + Kitchen and Rosenfeld response image. + + """ + + imx, imy = _compute_derivatives(image) + imxx, imxy = _compute_derivatives(imx) + imyx, imyy = _compute_derivatives(imy) + + response = (imxx * imy**2 + imyy * imx**2 - 2 * imxy * imx * imy) \ + / (imx**2 + imy**2) + + return response + + def corner_harris(image, method='k', k=0.05, eps=1e-6, sigma=1): """Compute Harris response image.