/harris-corner-detector

A simple implementation of the standard Harris corner detector in Matlab

Primary LanguageMATLABMIT LicenseMIT

Developed with Giuseppe Marino

Harris corner detector

Given an image where represents the coordinates of a pixel, it's possible to detect if the local neighbourhood of contains a corner by using the Harris corner detector.

The standard implementation works by using the autocorrelation matrix

where and are the partial derivatives of . The determinant and the trace of this matrix are high respectively when there is a corner and when there is an edge or corner. Thus, we can define the matrix such that when there is a corner and when there is an edge as

with a normalisation factor . We can then define a corner as a point in such that is a local maximum and that .

Implementation and usage

This implementation is only meant to be used to study the topic. It has a fixed value for k = 0.04 and takes t and n as parameters, where n represents the size of the window in which to perform the operations (e.g. if p is the center of the window and n = 2, then the window will go from p-2 to p+2 in both directions, so the size will be 5*5).

[H, keypoints, result] = harris(img, n, t);
figure; imshow(H, []);
figure; imshow(result);

The function takes a grayscale img and returns the matrix H of size [h, w], the list of keypoints which consists of two columns (representing the indexes i, j of each corner pixel), and the image result obtained by overlaying the keypoints (represented as red pixels) over the input image.


Original

Harris transform with n=3 and t=0.01

Original overlayed with keypoints (result)

About

The algorithm used comes from the section 2.1 in the paper Improving Harris corner selection strategy. The LaTeX syntax in this file is rendered with github-latex-markdown.