Compute Harris Corner Detector Response
The Harris Corner Detector identifies interest points by analyzing local image structure through the autocorrelation matrix A. The corner response R is calculated using:
R = det(A) - k Γ (trace(A))Β²
where:
- det(A) = Axx Γ Ayy - AxyΒ²
- trace(A) = Axx + Ayy
Given pre-computed gradient sums Axx, Ayy, Axy, and sensitivity constant k, calculate the Harris response R.
Constraints:
- k = 0.04 (default)
- Axx, Ayy, Axy are non-negative floats
- 0 β€ Axx, Ayy β€ 1000
Examples:
| Input | Output | |-------|--------| | Axx=100, Ayy=100, Axy=0, k=0.04 | 9600.0 | | Axx=500, Ayy=500, Axy=10, k=0.04 | 209600.0 |
Example:
Axx=100, Ayy=100, Axy=0, k=0.04
8400.0
- First, compute the determinant: det(A)=Axxββ AyyββAxy2β=100β 100β02=10000
- Then, compute the trace: trace(A)=Axxβ+Ayyβ=100+100=200
- Next, compute the penalty term: kβ (trace(A))2=0.04β 2002=0.04β 40000=1600
- Finally, compute the Harris response: R=det(A)βkβ (trace(A))2=10000β1600=8400.0, which matches the sample output.
1. Background Knowledge
The Harris Corner Detector (Harris & Stephens, 1988) is a fundamental algorithm for detecting interest points in images. It analyzes the local structure through the autocorrelation matrix (also called structure tensor):
A=[βIx2ββIxβIyβββIxβIyββIy2ββ]=[AxxβAxyββAxyβAyyββ]
where I_x and I_y are image gradients.
Harris Response Function: R=det(A)βkβ (trace(A))2
- det(A)=Axxββ AyyββAxy2β
- trace(A)=Axxβ+Ayyβ
- k is a sensitivity constant (typically 0.04-0.06)
Interpretation:
| Condition | Region Type |
|---|---|
| R > 0 (large) | Corner |
| R < 0 (large negative) | Edge |
| R |
2. Algorithm Approach
- Compute image gradients Ixβ, Iyβ using Sobel/Scharr operators
- Calculate products: Ix2β, Iy2β, IxβIyβ
- Apply Gaussian weighting to get Axxβ, Ayyβ, Axyβ
- Compute Harris response R at each pixel
- Apply non-maximum suppression to find corners
3. Step-by-Step Strategy
- Compute determinant: Axxββ AyyββAxy2β
- Compute trace: Axxβ+Ayyβ
- Apply formula: R=detβkβ \text{trace}2
4. Common Pitfalls
- Forgetting to square the trace
- Using wrong sign (det - ktraceΒ² not det + ktraceΒ²)
- Not handling negative results (edges have negative R)
5. Time & Space Complexity
| Aspect | Complexity |
|---|---|
| Time | O(1) for single pixel response |
| Space | O(1) |
For full image: O(nΒ²) where n is image dimension.