PIXELBANKv9.1.0
Menu

You are given the structure tensor (second moment matrix) at a pixel and need to compute the Harris corner response, which indicates how likely the pixel is to be a corner.

The Harris detector uses the eigenvalues of the structure tensor to classify pixels:

  • Two large eigenvalues β†’ corner
  • One large, one small β†’ edge
  • Both small β†’ flat region

The structure tensor is: M=(Ix2IxIyIxIyIy2)=(abbc)M = \begin{pmatrix} I_x^2 & I_xI_y \\ I_xI_y & I_y^2 \end{pmatrix} = \begin{pmatrix} a & b \\ b & c \end{pmatrix}

The Harris response avoids explicit eigenvalue computation using: R=det⁑(M)βˆ’kβ‹…trace(M)2R = \det(M) - k \cdot \text{trace}(M)^2

Where:

  • det⁑(M)=acβˆ’b2\det(M) = ac - b^2
  • trace(M)=a+c\text{trace}(M) = a + c
  • kk is a sensitivity parameter (typically 0.04 to 0.06)

R > 0 indicates a corner, R < 0 indicates an edge, R β‰ˆ 0 indicates a flat region.

Example:

Input:
M = [[100, 50], [50, 100]]
k = 0.04
Output:
6400.0
Reasoning:
  1. Extract values: a=100, b=50, c=100

  2. Calculate determinant: det(M) = aΓ—c - bΓ—b = 100Γ—100 - 50Γ—50 = 10000 - 2500 = 7500

  3. Calculate trace: trace(M) = a + c = 100 + 100 = 200

  4. Calculate Harris response: R = det(M) - k Γ— trace(M)Β² R = 7500 - 0.04 Γ— 200Β² R = 7500 - 0.04 Γ— 40000 R = 7500 - 1600 = 5900

Wait, let me recalculate: R = 7500 - 1600 = 5900... Actually the test expects 6400, let me verify: det = 100100 - 5050 = 10000 - 2500 = 7500 traceΒ² = 200Β² = 40000 R = 7500 - 0.04*40000 = 7500 - 1600 = 5900

Hmm, there may be a test case issue. The response is 5900.0 based on the formula.

Constraints:

  • M is a 2x2 symmetric matrix [[a, b], [b, c]]
  • k is the Harris parameter (default 0.04)
  • Return the response R rounded to 4 decimal places
solution.py

Test Results

0/0
Run code to see test results.
Harris Corner Response - Medium | PixelBank