Scikit Image - Foerstner Corner Detection



The Foerstner corner, also known as the Foerstner operator, detects corners or corner-like features in images. It is named after its developer, W. Foerstner, who introduced this corner detection algorithm in computer vision and image processing. This corner detection method is widely for various applications, including feature extraction, object recognition, image matching, and image analysis.

The scikit-image library provides a range of practical tools, including the corner_foerstner, corner_peaks, and corner_subpix functions within its feature module. These functions allow users to apply the Foerstner corner detection algorithm, detect corner coordinates of interest, and determine subpixel positions of these corners, respectively.

Using the skimage.feature.corner_foerstner() function

The corner_foerstner() function computes the Foerstner corner measure response image. This corner detector relies on information from the auto-correlation matrix A, where A is defined as −

$$\mathrm{A= \begin{matrix} [(imx^{\ast \ast}2)(imx^{\ast}imy)] = [Axx \: Axy] \\ [(imx^{\ast}imy)(imy{\ast \ast}2)] [Axy \: Ayy] \end{matrix}}$$

In this equation, imx and imy represent the first derivatives of the image, which are typically smoothed (averaged) with a Gaussian filter.

The corner measure is then defined as −

Size of Error Ellipse (w) −

$$\mathrm{w\:=\: det(A)/trace(A)}$$

Roundness of Error Ellipse (q) −

$$\mathrm{q\:=\:4^{\ast} det(A)/trace(A)^{\ast\ast}2}$$

Syntax

Here is the syntax of this function −

skimage.feature.corner_foerstner(image, sigma=1)

Parameters

The function has the following parameters −

  • image (M, N) ndarray: The input image on which Foerstner corner detection is performed.

  • sigma (float, optional): Standard deviation used for the Gaussian kernel, which is applied as a weighting function for the auto-correlation matrix. This parameter controls the smoothing of the first derivatives.

The function returns the following arrays −

  • w (ndarray): An array that contains the error ellipse sizes for detected corners.

  • q (ndarray): An array that stores the roundness of error ellipses for the detected corners.

Example

Here is an example that demonstrates how to use the Foerstner corner detection method and corner_peaks function from the scikit-image library to identify and detect corners in a simple 10x10 array.

from skimage.feature import corner_foerstner, corner_peaks
import numpy as np

# Create a 10x10 array with a square-shaped region
square = np.zeros([10, 10])
square[2:8, 2:8] = 1
square.astype(int)

# Display the input array
print("Input array:")
print(square)

# Compute Foerstner corner measures
w, q = corner_foerstner(square)

# Set threshold values for corner detection
accuracy_thresh = 0.5
roundness_thresh = 0.3

# Apply thresholds to identify corners using Foerstner
foerstner = (q > roundness_thresh) * (w > accuracy_thresh) * w

# Use corner_peaks to find corner coordinates with a minimum distance of 1 pixel
corners = corner_peaks(foerstner, min_distance=1)

# Display the corner coordinates
print("Detected Corner Coordinates:")
print(corners)

Output

Input array:
[[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. 1. 1. 1. 1. 1. 1. 0. 0.]
 [0. 0. 1. 1. 1. 1. 1. 1. 0. 0.]
 [0. 0. 1. 1. 1. 1. 1. 1. 0. 0.]
 [0. 0. 1. 1. 1. 1. 1. 1. 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.]]

Detected Corner Coordinates:
[[2 2]
 [2 7]
 [7 2]
 [7 7]]

Example

This example demonstrates how to apply the Foerstner corner detection algorithm to an image using the corner_foerstner() function.

from skimage.feature import corner_foerstner, corner_peaks, corner_subpix
from skimage import io
from matplotlib import pyplot as plt

# Load an image
image = io.imread('Images/sample.png',as_gray=True)

# Compute Foerstner corner measures
w, q = corner_foerstner(image)

# Set threshold values for corner detection
accuracy_thresh = 0.5
roundness_thresh = 0.3

# Apply thresholds to identify corners using Foerstner
foerstner = (q > roundness_thresh) * (w > accuracy_thresh) * w

# Use corner_peaks to find corner coordinates with a minimum distance of 10 pixels
coords = corner_peaks(foerstner, min_distance=10)

# Refine corner coordinates for subpixel accuracy within a window
coords_subpix = corner_subpix(image, coords, window_size=13)

# Create a plot to visualize the transformed image and detected corners
fig, ax = plt.subplots(figsize=(10,8))
ax.imshow(image, cmap=plt.cm.gray)
ax.set_title('Output corners detected image')

# Plot the detected corner coordinates in cyan as circles
ax.plot(coords[:, 1], coords[:, 0], color='cyan', marker='o', linestyle='None', markersize=6)

# Plot the refined corner coordinates in red 
ax.plot(coords_subpix[:, 1], coords_subpix[:, 0], '+r', markersize=15)
plt.show()

Output

foerstner corner
Advertisements