The Harris detector finds pixels where a small window's appearance changes strongly whichever way the window slides, using only first derivatives.
Gradients: central differences, with the image extended by mirror reflection without repeating the edge pixel (NumPy's reflect padding):
Ix[i,j]=21(I[i, j+1]−I[i, j−1]),Iy[i,j]=21(I[i+1, j]−I[i−1, j])
Structure tensor: smooth each of Ix2, IxIy and Iy2 with a normalized Gaussian of standard deviation σ and radius ⌈3σ⌉ (weights e−x2/(2σ2) divided by their sum), applied separably with the same mirror border, giving Sxx, Sxy, Syy.
Response:
R=SxxSyy−Sxy2−k(Sxx+Syy)2
Corners: pixel (i,j) is a corner when both hold:
- R[i,j]≥rel⋅maxR (the maximum over the whole image), and
- R[i,j] is the largest value of R in the (2radius+1)×(2radius+1) window centred on it (ties count as largest; window pixels outside the image are ignored).
If maxR≤0 there are no corners.
Implement structure_tensor(img, sigma) returning (Sxx, Sxy, Syy), harris_response(img, sigma=1.0, k=0.05), and harris_corners(img, sigma=1.0, k=0.05, rel=0.01, radius=1) returning a list of [row, col] pairs in raster order (sorted by row, then column). You may assume ⌈3σ⌉ is smaller than both image sides.