Harris Corner Detection

Imagine sliding a small window over a photograph. Ask a simple question: does the image content inside the window change when it shifts? Over a flat wall, nothing changes. Along an edge, sliding parallel to the edge produces no change. But sliding across it does. At a corner — the tip of a roof, the joint of a picture frame — shifting the window in any direction changes its content substantially. This intuition was formalized in 1988 by Chris Harris and Mike Stephens. It gives one of the most influential ideas in feature detection: a corner is a point of maximal local self-dissimilarity under small shifts. Corners matter because they are rare image locations. They are simultaneously localizable (a small perturbation of position looks different). They are also repeatable (the same physical point tends to trigger detection across viewpoints, lighting, and time). Flat regions give no constraint on position. Edges give only one-dimensional constraint (the aperture problem). Corners pin down position in both image dimensions. This is exactly what is needed for tasks like camera calibration, structure-from-motion, panorama stitching, visual odometry, and tracking. The Harris detector operationalizes this intuition through the second-moment matrix (also called the structure tensor). It is built from local image gradients. Its eigenvalues measure how much intensity varies along the two principal directions of local structure. A clever algebraic trick — the corner response function — avoids computing eigenvalues explicitly. It still classifies each pixel as flat, edge, or corner. The result is a detector that is simple, fast, rotation-invariant. It is also reasonably robust to small illumination and viewpoint changes. It seeded three decades of feature-based vision, from stereo matching to the descriptor pipelines used before deep learning. This article builds the second-moment matrix from first principles. It derives the corner response function and explains why it works without eigendecomposition. It gives complete pseudocode for non-maximum suppression and thresholding. It traces a worked numerical example. Finally, it previews how Harris corners motivate scale-invariant detectors like SIFT. It also shows how they feed directly into tracking algorithms like Lucas-Kanade Optical Flow.

Key takeaways
  • A corner is a point where shifting a small window in any direction changes the windowed image substantially — unlike flat regions (no change) or edges (change in one direction only).
  • The second-moment matrix MM, built from squared and cross gradients averaged over a window, summarizes local intensity variation as a 2×22\times2 symmetric matrix.
  • MM's eigenvalues λ1,λ2\lambda_1, \lambda_2 classify the pixel: both small → flat, one large one small → edge, both large → corner.
  • The Harris response R=det⁡(M)−k trace(M)2R = \det(M) - k\,\mathrm{trace}(M)^2 scores "cornerness" without computing eigenvalues explicitly, since det⁡M=λ1λ2\det M = \lambda_1\lambda_2 and trace M=λ1+λ2\mathrm{trace}\,M = \lambda_1+\lambda_2.
  • Detection = compute RR at every pixel, threshold, then apply non-maximum suppression to keep one point per corner.
  • Harris corners are rotation-invariant but not scale-invariant, which motivates scale-space extensions like SIFT Scale-Invariant Features.
The core insight

A corner is a pixel whose local neighborhood looks different when shifted in every direction, and this can be measured cheaply through the eigenvalue structure of a 2×22\times2 gradient covariance matrix.

The idea

Consider a small image patch centered at pixel (x,y)(x,y), and shift it by a displacement (u,v)(u,v). The auto-correlation (self-similarity) of the image under this shift is measured by the sum of squared differences between the original and shifted patch:

E(u,v)=∑(xi,yi)∈Ww(xi,yi) [I(xi+u, yi+v)−I(xi, yi)]2E(u,v) = \sum_{(x_i,y_i)\in W} w(x_i,y_i)\,\big[I(x_i+u,\,y_i+v) - I(x_i,\,y_i)\big]^2

where WW is a local window and ww is a weighting function (often a Gaussian, giving more importance to pixels near the center). If E(u,v)E(u,v) is small for all (u,v)(u,v) in some neighborhood of the origin, the patch is flat or nearly so under shifts — not a corner. If EE grows quickly in every direction, the point is a corner. To make this tractable, Taylor-expand the shifted image to first order:

I(xi+u,yi+v)≈I(xi,yi)+Ix(xi,yi) u+Iy(xi,yi) vI(x_i+u, y_i+v) \approx I(x_i,y_i) + I_x(x_i,y_i)\,u + I_y(x_i,y_i)\,v

where Ix,IyI_x, I_y are the horizontal and vertical image gradients. Substituting into EE:

E(u,v)≈∑Ww (Ixu+Iyv)2=(uv)M(uv)E(u,v) \approx \sum_W w\,\big(I_x u + I_y v\big)^2 = \begin{pmatrix} u & v \end{pmatrix} M \begin{pmatrix} u \\ v \end{pmatrix}

where MM is the second-moment matrix (structure tensor):

M=∑Ww(Ix2IxIyIxIyIy2)=(⟨Ix2⟩⟨IxIy⟩⟨IxIy⟩⟨Iy2⟩)M = \sum_{W} w \begin{pmatrix} I_x^2 & I_xI_y \\ I_xI_y & I_y^2 \end{pmatrix} = \begin{pmatrix} \langle I_x^2\rangle & \langle I_xI_y\rangle \\ \langle I_xI_y\rangle & \langle I_y^2\rangle \end{pmatrix}

Here ⟨⋅⟩\langle\cdot\rangle denotes the weighted local average over the window. MM is a real symmetric 2×22\times2 matrix, so it has an eigendecomposition M=R−1diag(λ1,λ2)RM = R^{-1}\mathrm{diag}(\lambda_1,\lambda_2)R with real eigenvalues λ1≥λ2≥0\lambda_1 \ge \lambda_2 \ge 0 (positive semi-definite because MM is a sum of outer products). Geometrically, E(u,v)≈λ1u′2+λ2v′2E(u,v) \approx \lambda_1 u'^2 + \lambda_2 v'^2 in the rotated coordinate frame aligned with MM's eigenvectors — an elliptical bowl whose axis lengths are governed by 1/λ1,1/λ21/\sqrt{\lambda_1}, 1/\sqrt{\lambda_2}. This yields a clean geometric classification:

  • λ1≈λ2≈0\lambda_1 \approx \lambda_2 \approx 0: flat region — the surface EE is nearly zero everywhere; no direction changes the patch.
  • λ1≫λ2≈0\lambda_1 \gg \lambda_2 \approx 0: edge — the bowl is a trough, flat along the edge direction (eigenvector for λ2\lambda_2), steep across it.
  • λ1≈λ2≫0\lambda_1 \approx \lambda_2 \gg 0: corner — the bowl is steep in every direction, so any shift increases EE substantially.

How it works

Computing eigenvalues at every pixel is possible but relatively expensive and requires care with numerical edge cases. Harris and Stephens's key trick is to score "cornerness" using only the trace and determinant of MM, both of which are cheap, closed-form functions of its entries and invariant under rotation:

det⁡(M)=λ1λ2,trace(M)=λ1+λ2\det(M) = \lambda_1 \lambda_2, \qquad \mathrm{trace}(M) = \lambda_1 + \lambda_2

The Harris corner response is defined as:

R=det⁡(M)−k⋅trace(M)2R = \det(M) - k \cdot \mathrm{trace}(M)^2

with kk an empirical sensitivity constant, typically k∈[0.04,0.06]k \in [0.04, 0.06]. Expanding in terms of eigenvalues:

R=λ1λ2−k(λ1+λ2)2R = \lambda_1\lambda_2 - k(\lambda_1+\lambda_2)^2
  • If both eigenvalues are small, both terms are small, so R≈0R \approx 0 (flat).
  • If one eigenvalue dominates (λ1≫λ2≈0\lambda_1 \gg \lambda_2 \approx 0), then λ1λ2≈0\lambda_1\lambda_2 \approx 0 but (λ1+λ2)2≈λ12(\lambda_1+\lambda_2)^2 \approx \lambda_1^2 is large, so RR becomes strongly negative (edge).
  • If both eigenvalues are large and comparable, λ1λ2\lambda_1\lambda_2 dominates over k(λ1+λ2)2k(\lambda_1+\lambda_2)^2 (since k<1/4k < 1/4 suppresses the square term relative to the product for balanced eigenvalues), so RR is positive and large (corner).

This gives a single scalar per pixel: large positive RR signals a corner, large negative RR signals an edge, and small ∣R∣|R| signals a flat region — without ever diagonalizing MM.

Full pipeline: 1. Compute image gradients Ix,IyI_x, I_y (e.g., via Sobel filters). 2. Form the products Ix2I_x^2, Iy2I_y^2, IxIyI_xI_y at every pixel. 3. Smooth each product with a Gaussian (or box) window to get the windowed sums ⟨Ix2⟩,⟨Iy2⟩,⟨IxIy⟩\langle I_x^2\rangle, \langle I_y^2\rangle, \langle I_xI_y\rangle — this is the local averaging that assembles M(x,y)M(x,y) per pixel. 4. Compute R(x,y)=det⁡M−k trace(M)2R(x,y) = \det M - k\,\mathrm{trace}(M)^2 at every pixel. 5. Threshold RR to keep only strong positive responses. 6. Apply non-maximum suppression so each physical corner yields one detected point rather than a cluster. ``` function HARRIS_CORNERS(I, window_sigma, k, threshold, nms_radius):

# Step 1: gradients Ix, Iy <- SOBEL_GRADIENTS(I)

# Step 2: gradient products Ixx <- Ix Ix Iyy <- Iy Iy Ixy <- Ix * Iy

# Step 3: windowed sums (structure tensor entries), per pixel Sxx <- GAUSSIAN_BLUR(Ixx, window_sigma) Syy <- GAUSSIAN_BLUR(Iyy, window_sigma) Sxy <- GAUSSIAN_BLUR(Ixy, window_sigma) R <- array of zeros, same shape as I

# Step 4: response function, per pixel for each pixel (x, y): det_M <- Sxx[x,y] Syy[x,y] - Sxy[x,y]^2 trace_M <- Sxx[x,y] + Syy[x,y] R[x,y] <- det_M - k trace_M^2

# Step 5: threshold candidates <- { (x,y) : R[x,y] > threshold }

# Step 6: non-maximum suppression corners <- [] for (x, y) in candidates, sorted by R[x,y] descending: if R[x,y] is the maximum value of R within the (2nms_radius+1)x(2nms_radius+1) neighborhood of (x,y): corners.append((x, y, R[x,y])) return corners ``` Non-maximum suppression matters because RR varies smoothly near a true corner, producing many nearby pixels above threshold; without suppression, the detector would report a blob of points instead of one location per corner.

Figure
From gradients to a classified pixel: building M and reading its eigenvalue geometry
Local window W I(x,y), Iₓ, I_y M (2x2 structure tensor) ⟨Iₓ²⟩ ⟨IₓI_y⟩ ⟨IₓI_y⟩ ⟨I_y²⟩ weighted local sums Local shape of E(u,v) flat: λ₁≈λ₂≈0 edge: λ₁≫λ₂ corner: λ₁≈λ₂≫0 R = det(M) − k·trace(M)² R ≪ 0 → edge R ≈ 0 → flat R ≫ 0 → corner

Complexity & correctness

Time complexity. Let the image have N=W×HN = W \times H pixels and let the smoothing/gradient kernels have fixed size (independent of NN, e.g. a 5×55\times5 Gaussian). Every stage — gradient computation, forming products, Gaussian smoothing, computing RR, thresholding — touches each pixel a constant number of times with a constant-size convolution kernel. Hence the entire pipeline is:

O(N) time (for fixed kernel size)O(N) \text{ time (for fixed kernel size)}

If the smoothing kernel is separable (Gaussians are) and has spatial extent kk, exact convolution costs O(Nk)O(Nk) using two 1D passes rather than O(Nk2)O(Nk^2) for a naive 2D convolution — a standard and important constant-factor optimization, but it does not change the asymptotic linearity in NN. Non-maximum suppression over a window of radius rr costs O(Nr2)O(Nr^2) naively, or O(N)O(N) amortized with a sliding-window maximum algorithm (e.g., using a monotonic deque per row and per column), since rr is a fixed small constant in practice.

Space complexity. All intermediate arrays (Ix,Iy,Ix2,Iy2,IxIy,Sxx,Syy,Sxy,RI_x, I_y, I_x^2, I_y^2, I_xI_y, S_{xx}, S_{yy}, S_{xy}, R) are the same size as the image, so space is O(N)O(N); in an optimized streaming implementation, several of these can be computed and discarded row-by-row, but the asymptotic bound remains O(N)O(N).

Correctness argument. The core claim is that E(u,v)≈u⊤MuE(u,v) \approx u^\top M u is a faithful local model of auto-correlation, and that the sign/magnitude pattern of (λ1,λ2)(\lambda_1, \lambda_2) correctly separates flat/edge/corner regions. Three facts underwrite this: 1. Positive semi-definiteness of MM. MM is a weighted sum of rank-1 outer products (IxIy)(IxIy)\begin{pmatrix}I_x\\I_y\end{pmatrix}\begin{pmatrix}I_x&I_y\end{pmatrix} with nonnegative weights w≥0w \geq 0. A nonnegative sum of PSD matrices is PSD, so λ1,λ2≥0\lambda_1,\lambda_2 \geq 0 always — the model never predicts a decreasing EE, consistent with EE being a sum of squares. 2. Rotation invariance. det⁡(M)\det(M) and trace(M)\mathrm{trace}(M) are invariant under any orthogonal change of coordinates (rotating the image), since det⁡\det and trace are similarity-invariants: det⁡(P⊤MP)=det⁡(M)\det(P^\top M P) = \det(M) and trace(P⊤MP)=trace(M)\mathrm{trace}(P^\top M P) = \mathrm{trace}(M) for orthogonal PP. Therefore RR, and hence the corner classification, does not depend on the orientation of the image or the local gradient directions — a genuine rotational invariance, not merely an approximate one. 3. RR correctly orders the three regimes for k<1/4k < 1/4. Write R=λ1λ2−k(λ1+λ2)2R = \lambda_1\lambda_2 - k(\lambda_1+\lambda_2)^2. Substituting the ratio ρ=λ2/λ1∈[0,1]\rho = \lambda_2/\lambda_1 \in [0,1] (assuming λ1≥λ2≥0\lambda_1 \geq \lambda_2 \geq 0, λ1>0\lambda_1 > 0):

R=λ12[ρ−k(1+ρ)2]R = \lambda_1^2\big[\rho - k(1+\rho)^2\big]

The bracket is positive when ρ\rho is close to 1 (comparable eigenvalues — corner) and negative when ρ→0\rho \to 0 (one eigenvalue vanishes — edge), for any k∈(0,1/4)k \in (0, 1/4), because at ρ=1\rho=1 the bracket equals 1−4k>01 - 4k > 0, and at ρ=0\rho = 0 it equals −k<0-k < 0, with the bracket monotonically increasing in ρ\rho on [0,1][0,1] (its derivative is 1−2k(1+ρ)>1−4k>01 - 2k(1+\rho) > 1 - 4k > 0). This proves the sign of RR transitions exactly once as ρ\rho increases from 0 to 1, validating RR's use as a corner/edge discriminator for the standard choice of kk.

Honest tradeoffs. The first-order Taylor expansion of E(u,v)E(u,v) is only locally accurate; for large shifts or highly curved intensity surfaces it degrades, but Harris only needs the local quadratic shape near u=v=0u=v=0, so this is not a practical limitation. The constant kk is empirical, not derived from first principles, and different values shift the edge/corner boundary. Gaussian window size trades off localization (small window, precise but noise-sensitive) against robustness (large window, smooth but blurs nearby corners together). Most importantly, the detector is invariant to rotation and (to a good approximation) to affine intensity changes, but not scale-invariant: a corner detected at one image resolution may vanish or shift at another, motivating scale-space treatments such as SIFT Scale-Invariant Features.

Worked example

Consider a synthetic 5×55\times 5 grayscale patch containing a clean right-angle corner (bright region in the top-right, dark elsewhere), centered on the pixel of interest:

I=(0001001000001001000001001000000000000)I = \begin{pmatrix} 0 & 0 & 0 & 100 & 100\\ 0 & 0 & 0 & 100 & 100\\ 0 & 0 & 0 & 100 & 100\\ 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0 \end{pmatrix}

The corner of the bright region sits near pixel (3,2)(3,2) (0-indexed columns, rows). Compute simple forward-difference gradients Ix=I(x+1,y)−I(x,y)I_x = I(x+1,y) - I(x,y), Iy=I(x,y+1)−I(x,y)I_y = I(x,y+1)-I(x,y) over a 3×33\times3 window centered at (3,2)(3,2), using a uniform (unweighted) window for simplicity:

pixel (x,y)IxI_xIyI_yIx2I_x^2Iy2I_y^2IxIyI_xI_y
(2,1)10001000000
(3,1)00000
(4,1)00000
(2,2)100-1001000010000-10000
(3,2)0-1000100000
(4,2)0-1000100000
(2,3)00000
(3,3)00000
(4,3)00000

Sum the columns to get the (unweighted) second-moment matrix entries:

∑Ix2=20000,∑Iy2=30000,∑IxIy=−10000\textstyle\sum I_x^2 = 20000,\quad \sum I_y^2 = 30000,\quad \sum I_xI_y = -10000
M=(20000−10000−1000030000)M = \begin{pmatrix} 20000 & -10000 \\ -10000 & 30000 \end{pmatrix}

Compute det⁡(M)\det(M) and trace(M)\mathrm{trace}(M) directly (no eigendecomposition needed):

det⁡(M)=(20000)(30000)−(−10000)2=6×108−1×108=5×108\det(M) = (20000)(30000) - (-10000)^2 = 6\times10^8 - 1\times10^8 = 5\times10^8
trace(M)=20000+30000=50000\mathrm{trace}(M) = 20000 + 30000 = 50000

With k=0.04k = 0.04:

R=5×108−0.04×(50000)2=5×108−0.04×2.5×109=5×108−1×108=4×108R = 5\times10^8 - 0.04\times(50000)^2 = 5\times10^8 - 0.04\times2.5\times10^9 = 5\times10^8 - 1\times10^8 = 4\times10^8

R>0R > 0 and large — the pixel is correctly classified as a corner. For comparison, repeat the same computation centered at pixel (3,1)(3,1), which sits on the vertical edge between dark and bright regions but away from the corner tip. There, gradients are strong horizontally (Ix≈100I_x \approx 100) but Iy≈0I_y \approx 0 throughout the window, giving roughly M≈diag(20000,0)M \approx \mathrm{diag}(20000, 0), so det⁡(M)≈0\det(M) \approx 0, trace(M)≈20000\mathrm{trace}(M) \approx 20000, and:

R≈0−0.04×(20000)2=−1.6×107R \approx 0 - 0.04\times(20000)^2 = -1.6\times10^7

Strongly negative RR — correctly classified as an edge, exactly as the theory predicts.

Common pitfalls & traps

PitfallWhy it happensConsequenceFix
Skipping the smoothing/windowing stepTreating MM as pointwise (Ix2IxIyIxIyIy2)\begin{pmatrix}I_x^2 & I_xI_y\\ I_xI_y & I_y^2\end{pmatrix} without averagingRank-1 matrix everywhere (det⁡M≡0\det M \equiv 0); every pixel looks like an edge or flat, corners vanishAlways convolve the gradient products with a window (Gaussian or box) before forming MM
Using too small a Gaussian windowWindow barely larger than gradient supportVery noise-sensitive RR, spurious corners from sensor noiseIncrease σ\sigma or pre-blur the image slightly
No non-maximum suppressionThresholding RR aloneDozens of adjacent pixels near a true corner all pass threshold, reported as separate detectionsSuppress non-maxima within a fixed radius before returning corner list
Wrong sign convention or forgetting kkConfusing det⁡−k trace2\det - k\,\mathrm{trace}^2 with det⁡/trace\det/\mathrm{trace} or omitting kk entirelyEdge pixels misclassified as weak corners, or threshold tuning becomes meaninglessUse the exact formula R=det⁡(M)−k trace(M)2R=\det(M)-k\,\mathrm{trace}(M)^2 with k∈[0.04,0.06]k\in[0.04,0.06]
Assuming scale invarianceTreating Harris corners like SIFT keypoints across pyramid levels naivelySame physical corner detected at wildly different image scales, or missed entirely after resizingExplicitly build a scale-space (Harris-Laplace) if scale invariance is needed
Comparing RR thresholds across images with different contrastRR scales with λ1λ2∼(intensity)4\lambda_1\lambda_2 \sim (\text{intensity})^4A fixed absolute threshold works on one image but fails on a brighter/dimmer oneNormalize gradients, or use adaptive/relative thresholds (e.g., top-NN responses)

Pioneers & history

The Harris detector emerged from British computer vision research in the late 1980s, building on Hans Moravec's earlier "cornerness" measure, which used four discrete shift directions and suffered from anisotropy and noise sensitivity. Harris and Stephens generalized Moravec's idea to continuous shifts via the Taylor expansion and the second-moment matrix, producing an operator that is smooth, rotation-invariant, and robust — properties Moravec's discrete version lacked.

Origins · 1 minChris Harris and how this was discovered
CH
Chris Harris
active from the 1980s, Plessey Research / University of Oxford · Co-developed the Harris–Stephens corner and edge detector (1988) for real-time visual tracking and structure-from-motion in robotics

History
1977
— Hans Moravec introduces a discrete corner detector for robot navigation, using sum-of-squared-differences over four fixed shift directions.
1988
— Chris Harris and Mike Stephens publish "A Combined Corner and Edge Detector," introducing the second-moment matrix and the R=det⁡(M)−k trace(M)2R = \det(M)-k\,\mathrm{trace}(M)^2 response.
1994
— Jianbo Shi and Carlo Tomasi propose the "Good Features to Track" criterion, using the minimum eigenvalue of MM directly rather than the Harris response.
2004
— David Lowe's SIFT builds scale-invariant keypoints atop ideas closely related to Harris-style local structure analysis, combined with a scale-space extremum search.
2006
onward — Harris-style corner/structure-tensor responses are absorbed into learned feature detectors (e.g., convolutional keypoint networks), while remaining a standard baseline and classroom introduction to local feature detection.

Where this matters

Harris corners (and its direct descendants, the Shi–Tomasi "minimum eigenvalue" criterion and Harris-Laplace scale-space variants) are foundational building blocks across classical and modern vision pipelines. Camera calibration routines use them to locate checkerboard corners precisely. Structure-from-motion and visual SLAM systems use Harris-style corner scores to select trackable points before running Lucas-Kanade Optical Flow or feature matching across frames, since a good track requires a point that is locally distinctive in both image dimensions. Panorama stitching software historically detected Harris corners as candidate keypoints before computing rotation- and scale-invariant descriptors around them. Optical flow and KLT (Kanade–Lucas–Tomasi) trackers explicitly select points to track using the eigenvalues of the same second-moment matrix, since a well-conditioned MM (both eigenvalues large) is precisely the condition under which the optical flow equations are numerically stable — the corner criterion and the "good point to track" criterion are, mathematically, the same object viewed from two purposes. Even in the deep learning era, learned keypoint detectors (e.g., SuperPoint-style networks) are frequently evaluated against Harris corners as a classical baseline, and the underlying structure-tensor idea persists in edge-aware image filters and anisotropic diffusion.

Ask the tutor: How does the Harris corner response change if the image is rotated by 45° — and why does the math guarantee the same corners are detected?

Why is det(M) − k·trace(M)² preferred over just using the smaller eigenvalue λ₂ (the Shi–Tomasi criterion)?

Both are valid corner scores, and in practice they behave similarly. Harris and Stephens chose det⁡(M)−k trace(M)2\det(M)-k\,\mathrm{trace}(M)^2 because it avoids explicit eigendecomposition, which in 1988 was computationally more expensive relative to a couple of multiplications and additions. The Shi–Tomasi criterion, RST=min⁡(λ1,λ2)R_{ST}=\min(\lambda_1,\lambda_2), requires solving the quadratic characteristic equation of a 2×22\times2 matrix, which is cheap today but was a meaningful cost difference historically. Empirically, Shi–Tomasi's criterion is considered slightly more principled for selecting points to track (it directly measures the worst-case direction), and is the default in many optical-flow implementations, while the original Harris formula remains extremely common as a general-purpose corner detector.

Does the Harris detector work on color images, or does it require grayscale?

The standard formulation operates on a single-channel intensity image, so color images are typically converted to grayscale first, and gradients Ix,IyI_x, I_y are computed on that channel. Extensions exist that build a combined structure tensor from gradients of all three color channels (summing per-channel outer products before forming MM), which can detect corners that are visible only as a color change with little luminance change. These color-aware variants are less common in practice because grayscale gradients already capture the vast majority of usable corner structure in typical photographs, and the added complexity rarely pays for itself outside specialized applications.

How should the threshold on R be chosen in practice?

There is no universal constant threshold, because RR's magnitude scales with image contrast and gradient units, roughly as intensity to the fourth power near a corner. Two common strategies avoid hand-tuning: use an adaptive threshold relative to the maximum RR observed in the image (e.g., keep pixels with R>0.01×Rmax⁡R > 0.01 \times R_{\max}), or simply keep the top-NN responses after non-maximum suppression, which is scale-of-RR-independent and directly controls how many features downstream algorithms must process. Both strategies are widely used in practice, often combined with a hard floor to reject essentially flat regions.

Is the Harris detector robust to illumination changes?

It is robust to additive brightness shifts, since gradients Ix,IyI_x, I_y are differences and a constant offset added to every pixel does not change them. It is only approximately robust to multiplicative gain changes (uniform brightening or darkening), since scaling intensity by a constant cc scales Ix,IyI_x, I_y by cc, which scales MM by c2c^2 and RR by c4c^4 — the corner/edge/flat classification is preserved because it depends only on the ratio λ2/λ1\lambda_2/\lambda_1, but the raw magnitude of RR shifts, which matters for a fixed absolute threshold. It has no special robustness to non-uniform illumination (shadows, specular highlights), which can create or destroy apparent corners.

Why isn't the Harris detector scale-invariant, and what breaks if the image is resized?

The gradients Ix,IyI_x, I_y and the window size WW are computed at a fixed pixel scale. If the same physical corner is imaged at higher resolution, its gradient values, window statistics, and hence its RR score all change in ways that do not correspond simply to the lower-resolution values. A corner that is sharp at one zoom level may appear rounded and sub-threshold at another, or the window may span multiple physical corners instead of one. This is precisely the gap that scale-space approaches close: by searching for the characteristic scale at which a Laplacian-of-Gaussian response is extremal (as in Harris-Laplace, and more elaborately in SIFT Scale-Invariant Features), a detector can report both a location and a scale, making detections comparable across zoom.

How does the Harris second-moment matrix relate to optical flow tracking?

The Lucas-Kanade method for Lucas-Kanade Optical Flow estimates a local displacement (u,v)(u,v) by solving the linear system M(uv)=(−∑IxIt−∑IyIt)M\begin{pmatrix}u\\v\end{pmatrix} = \begin{pmatrix}-\sum I_xI_t\\-\sum I_yI_t\end{pmatrix}, where MM is exactly the same second-moment matrix used by the Harris detector, built from spatial gradients over a window. Solving this system requires MM to be well-conditioned, i.e., both eigenvalues bounded away from zero — precisely the Harris "corner" condition. This is why Harris (or Shi–Tomasi) corners are the standard choice of points to track: they are, by construction, exactly the locations where the optical flow equations are numerically stable and the resulting displacement estimate is trustworthy.

What role does the smoothing/window function w play, and does the choice (box vs. Gaussian) matter much?

The window function determines which nearby gradient samples contribute to MM at a given pixel and with what weight. A box window treats all pixels within a fixed radius equally and can produce artifacts at the window boundary (sudden inclusion/exclusion of gradient information as the window slides by one pixel). A Gaussian window weights nearby pixels more heavily and tapers smoothly to zero, giving a continuously-varying, less noise-sensitive MM as a function of position, which is why Gaussian weighting is the standard choice in modern implementations. The Gaussian's σ\sigma acts as a scale parameter: larger σ\sigma pools information over a bigger neighborhood, trading precise localization for robustness to noise and to fine-scale texture that might otherwise register as spurious corners.

Before this

Where this leads