Table of contents
1.
Introduction
2.
Harris Corner Detection
2.1.
Algorithm 
3.
Implementation 
4.
Advantages and Disadvantages
5.
Applications
6.
FAQs
7.
Key Takeaways
Last Updated: Aug 13, 2025
Easy

Harris Corner Detection

Author Arun Nawani
1 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Deep Learning algorithms find their uses in almost every technology we use today. Smartphones are capable enough to give exact measurements of objects around you. They’re able to trace the objects in the images quite accurately. There are various deep learning algorithms that make it happen. One such algorithm is Harris Corner Detection, which would be the centre of discussion of this blog. 

Harris Corner Detection

Harris Corner Detection, also known as Harris and Stephens Corner detector, is one of the simplest and most commonly used corner detection algorithms. Before diving into the working, let’s first understand what makes a corner. A corner is formed where 2 edges meet. Harris corner detection makes use of this very fundamental concept. The idea is to locate interest points from where there are edges stretching into more than one direction. The algorithm works by computing the difference in intensity for a displacement in all directions. The expression for which is given by-

Source - link

The window function could be a rectangular window or could be a Gaussian window which gives weights to pixels at (x,y). Applying Taylor's expansion we get. 

Source - link

Denoting the summed matrix with M.

Source - link

The final equation is given as -

 

Source - link

Here, 

Ix, Iare the image derivatives in x and y directions. 

The harris response R is given by:

Source - link

Here, 

Source - link

A,B and C are window shifts defined by w. Lambdas represent the eigen values of m. 

K is the sensitivity factor to differentiate corner from edges. Small values of k result in the detection of sharp corners.

Source-link

The corners are found using value of R.

Algorithm 

  1. Convert the colour image to grayscale. 
  2. Compute the spatial derivatives, that is, Ix(horizontal derivative) and Iy(vertical derivative). 
  3. Structure the tensor setup(IxIx, IyIy, and IxIy). 
  4. Compute the Harris response(R). 
  5. Find the edges using R values. 

Implementation 

The sample image we’ve used can be found here

We’ll first convert it to grayscale.

from skimage.io import imread
from skimage.color import rgb2gray

img = imread('resources/box.jpg')
imggray = rgb2gray(img)
You can also try this code with Online Python Compiler
Run Code

 

Computing the spatial derivatives. 

from scipy import signal as sig
import numpy as np

def gradient_x(imggray):
    ##Sobel operator kernels.
    kernel_x = np.array([[-1, 0, 1],[-2, 0, 2],[-1, 0, 1]])
    return sig.convolve2d(imggray, kernel_x, mode='same')
def gradient_y(imggray):
    kernel_y = np.array([[1, 2, 1], [0, 0, 0], [-1, -2, -1]])
    return sig.convolve2d(imggray, kernel_y, mode='same')

I_x = gradient_x(imggray)
I_y = gradient_y(imggray)
You can also try this code with Online Python Compiler
Run Code

 

Structure tensor setup

Ixx = ndi.gaussian_filter(I_x**2, sigma=1)
Ixy = ndi.gaussian_filter(I_y*I_x, sigma=1)
Iyy = ndi.gaussian_filter(I_y**2, sigma=1)
You can also try this code with Online Python Compiler
Run Code

 

Computing Harris response

k = 0.05

# determinant
detA = Ixx * Iyy - Ixy ** 2
# trace
traceA = Ixx + Iyy
    
harris_response = detA - k * traceA ** 2
You can also try this code with Online Python Compiler
Run Code

 

Finding edges and corners using value of R.

For Edge : R < 0

For Corner : R > 0

For Flat: R = 0

img_copy_for_corners = np.copy(img)
img_copy_for_edges = np.copy(img)

for rowindex, response in enumerate(harris_response):
    for colindex, r in enumerate(response):
        if r > 0:
            # this is a corner
            img_copy_for_corners[rowindex, colindex] = [255,0,0]
        elif r < 0:
            # this is an edge
            img_copy_for_edges[rowindex, colindex] = [0,255,0]
You can also try this code with Online Python Compiler
Run Code

 

Grouping the corners into one point

You can see there are multiple corners points found in the image, we need to find the local maxima of the corner points. there is a method in skimage which does a neat job in finding the peaks.

#Harris corner detection using skimage library
from skimage.feature import corner_harris, corner_peaks
coords = corner_peaks(skimage_harris_response)

fig, ax = plt.subplots()
ax.imshow(img, interpolation='nearest', cmap=plt.cm.gray)
ax.plot(coords[:, 1], coords[:, 0], '.r', markersize=3)
You can also try this code with Online Python Compiler
Run Code

 

Advantages and Disadvantages

The biggest advantage of Harris Corner Detector is that its invariant to factors like rotation, translation, and changes in illumination which makes it the first choice for image data retrieval and stereomatching. It is the most repetitive and most informative among other known corner detection algorithms. 

The one big drawback of harris corner detection is that we need to set different threshold values for every image in order to detect the most prominent interest points. If the threshold value used is too low, then the algorithm may end up detecting large amount of points with noisy image data. 

Applications

Harris corner detection is used commonly used in day-to-day tasks. 

  • It is used for image alignment, stitching and registration. 
  • It can be used for creating 2D mosaics. 
  • It is used in 3D modelling. 
  • It is used in object detection and motion detection. 
    Also read, Sampling and Quantization

FAQs

  1. Mention some of the commonly used corner detection algorithms.
    Other than Harris Corner detection, other corner detection techniques are  - Susan Corner detection, Moravec Corner detection, Förstner corner detection, and Robust Fuzzy Rule Corner Detection. 
     
  2. How do R values determine a feature? 
    For R < 0, It is an edge. 
    For R > 0, it is a corner. 
    For R = 0, it is a flat. 
     
  3. How do eigen values vary with different features?
    For a flat region, both the eigen values are small.
    For an edge, one of the eigen values is significantly large and the other one is small. 
    For a corner, both the eigen values are large. 

Key Takeaways

Harris corner detection is a commonly used computer vision algorithm for corner extraction and inferring features in an image. This blog explains the algorithm in detail along with its implementation and its limitations. Readers are advised to go through the blog a couple of times to have a better grasp over the details. If you want to deep dive into machine learning and deep learning, check out our industry-oriented Machine learning course curated by Stanford University alumni and industry experts. 

Live masterclass