Skip to content

Shi-Tomasi

Fact Value
Also called Good features to track, Minimum eigenvalue corner detector
Status Implemented and tested
Family Texture, corners, blobs and features
Engine Browser
Type Nonlinear, spatial, structure tensor and smallest eigenvalue
Output Image
Operator shown as algorithm (exact)
Support radius 1 + floor(4 sigma + 0.5), plus the minimum distance for the corners output
Code web/src/core/filters/features/corners.ts, shiTomasiFilter
Operator code web/src/core/filters/features/corners.ts, cornerResponse
Channels Brightness only, RGB

Overview

The Shi-Tomasi detector finds corners by the smaller eigenvalue of the structure tensor. Shi and Tomasi chose it as the measure of a good feature to track: a window can be followed well only when the brightness changes in every direction. The filter shows the measure at every pixel, or the corner points themselves.

Three panels: a checkerboard, the Shi-Tomasi response with bright spots where four squares meet, and the corner points as nine white dots at those places. Three panels: a checkerboard, the Shi-Tomasi response with bright spots where four squares meet, and the corner points as nine white dots at those places.
Shi-Tomasi on a checkerboard. The response peaks where four squares meet, and the corner points mark those peaks.

How it works

  1. Compute the change in x and in y at every pixel.
  2. Collect the squares and the product of the two changes in a Gaussian window. This is the structure tensor.
  3. Score each pixel by the smaller eigenvalue of the tensor.
  4. For corner points, keep the local maxima above the threshold.

Mathematical foundation

\[ \begin{gathered} A = G_{\sigma} * \begin{pmatrix} I_x^2 & I_x I_y \\ I_x I_y & I_y^2 \end{pmatrix},\qquad R = \lambda_{\min}(A) = \tfrac{1}{2}\left(\operatorname{tr} A - \sqrt{(A_{xx} - A_{yy})^2 + 4 A_{xy}^2}\right) \end{gathered} \]

The formula shows the default parameter values.

where

  • \(A\): The structure tensor
  • \(I_x, I_y\): The Sobel derivatives
  • \(G_{\sigma}\): The Gaussian window

I_x and I_y are the Sobel derivatives of the image on a 0 to 1 scale. G_sigma * blurs each entry of the matrix with a Gaussian, so A sums the gradients around each pixel. A has two large eigenvalues at a corner, one at an edge and none in a flat area. Shi and Tomasi used the smaller eigenvalue, which is large only when the brightness changes in every direction. The corners output marks pixels whose response is at least the threshold and at least every response within the minimum distance. Plateaus keep every pixel. This is the rule of the filter, and it differs from skimage.feature.corner_peaks, which also drops corners near the border.

The structure tensor A has two eigenvalues. The larger one measures the change in the strongest direction, and the smaller one the change in the weakest direction. At a corner both are large, along an edge only the larger one is, and in a flat area both are small. So the smaller eigenvalue alone separates corners from the rest. Unlike Harris, it needs no extra parameter.

Kernel or operator

There is no single kernel. The Inspector lists the stages with the current sigma. The Sobel and Gaussian kernels are on their own pages.

Algorithm

  1. Extend the image by the support with the border mode and scale it to 0 to 1.
  2. Compute the Sobel derivatives and the three products.
  3. Blur each product with the Gaussian to get the structure tensor.
  4. Compute the smaller eigenvalue of A.
  5. For corner points, keep the local maxima above the threshold, and cut the extension off.

Parameters

Parameter Default Values Meaning
Sigma sigma 1 0.5 to 5 px The size of the Gaussian window over which the gradients are collected. It ends at 4 sigma.
Output output Corner response Corner response, Corner points The response at every pixel, or the corner points as white pixels.
Threshold threshold 0.01 0 to 10 The smallest response that counts as a corner. The response is computed on a 0 to 1 scale.
Minimum distance distance 3 1 to 20 px A corner must have the largest response within this many pixels in x and in y.
Output mapping outputMapping Stretch to full range Absolute value, Offset by 128, Stretch to full range, Clip to 0 to 255 How signed results, such as gradients, become 8-bit pixel values.
Border mode border Reflect 101 (default) Reflect 101 (default), Reflect, Replicate, Constant (zero), Wrap How pixels outside the image are filled when the window reaches past the edge.
Channels channelScope Brightness only RGB, Brightness only Which part of the color image the filter changes.

Implementation

cornerResponse in web/src/core/filters/features/corners.ts scales the plane to 0 to 1 and computes the Sobel derivatives. It blurs their products with a Gaussian cut at 4 sigma, as skimage.feature.structure_tensor does. The filter extends the plane once by the full support with the border mode, runs these stages and cuts the extension off. Then cornerPeaks keeps the pixels whose response is at least the threshold and the largest within the minimum distance. The filter runs in the browser engine, in Web Workers, through the shared filter framework in web/src/core/filters/run.ts, which handles the channel scope, alpha and the output mapping. By default it works on luma.

Worked example

Pixel x y Response
Flat area 3 3 0
Edge 10 17 0
Corner 10 10 1.2000

A 21 x 21 image, 50 everywhere except a bright quadrant of 200 from x = 10 and y = 10, with sigma 1. The image is read on a 0 to 1 scale. The smaller eigenvalue is 0 in the flat area and on the straight edge, where only one direction changes. It is large only at the corner.

Complexity

  • Time: \(O(N r)\)
  • Memory: \(O(N)\)

N is the number of pixels per channel and r the radius of the Gaussian, which is separable.

Artifacts and limitations

Limitations

  • Not scale invariant. One sigma fits one corner size.
  • The response grows with contrast, so one threshold does not suit dark and bright regions alike.

Artifacts

  • Clusters of responses along strongly curved edges.

Tests

The reference runs scipy.ndimage.sobel and scipy.ndimage.gaussian_filter on the extended plane and scipy.ndimage.maximum_filter for the peaks. Before the cases are written, the script checks the response against skimage.feature.corner_shi_tomasi on a larger random image away from the border, where both border rules give the same values. It also checks that a bright square gives exactly four corner points, one next to each of its corners. The cases cover the response and the corner points for all five border modes.

References