v9.1.1
Menu

FAST Corner Detector (Simplified)

hardPROFeature DetectorsFeaturesCV: Feature Detection and Matching

Implement a simplified version of the FAST (Features from Accelerated Segment Test) corner detector.

FAST detects corners by examining pixels on a circle around each candidate point. A point is a corner if a sufficient number of contiguous pixels on the circle are all brighter (or all darker) than the center by at least a threshold.

The algorithm uses a circle of 16 pixels at radius 3:

  • Positions: (-3,0), (-3,1), (-2,2), (-1,3), (0,3), (1,3), (2,2), (3,1), (3,0), (3,-1), (2,-2), (1,-3), (0,-3), (-1,-3), (-2,-2), (-3,-1)

For each pixel:

  1. Get the intensity of all 16 circle pixels
  2. Check if N or more contiguous pixels are all brighter than center + threshold
  3. OR check if N or more contiguous pixels are all darker than center - threshold
  4. If either condition is met, it's a corner

Note: The circle wraps around (position 15 is contiguous with position 0).

Example

Input
image = [[50,50,50,50,50,50,50],
        [50,50,50,50,50,50,50],
        [50,50,50,50,50,50,50],
        [50,50,50,200,50,50,50],
        [50,50,50,50,50,50,50],
        [50,50,50,50,50,50,50],
        [50,50,50,50,50,50,50]]
threshold = 40
n = 12
Output
[(3, 3)]
Reasoning
  • Inputs: image is a 7×77 \times 7 grid, all 5050 except one pixel of 200200 at row 33, column 33. threshold =40= 40 is the required gap, and n =12= 12 is the run length needed.
  • Which centres qualify: a radius-3 circle only fits when both row and column lie in [3,7−3)[3, 7-3), so (3,3)(3, 3) is the one and only candidate in this image.
  • Bright and dark bands: with centre Ic=200I_c = 200, a circle pixel counts as brighter if Ip>200+40=240I_p > 200 + 40 = 240 and darker if Ip<200−40=160I_p < 200 - 40 = 160.
  • The circle: all 16 offsets land on pixels of value 5050. None exceed 240240, but every one satisfies 50<16050 < 160, so the darker run has length 16≥1216 \ge 12. The centre is a corner.
  • Output: [(3, 3)], a list of (row, col) pairs.
  • Notice: both inequalities are strict. With threshold =150= 150 the dark band would need Ip<50I_p < 50, and 50<5050 < 50 is false, so the same image would return [].

Constraints

  • image is a 2D grayscale image (integer values)
  • threshold is the intensity difference required
  • n is the number of contiguous pixels required (default 12)
  • Return list of (row, col) corner coordinates
  • Only check pixels where a full circle fits (row and col >= 3 and < size-3)

Learn this in

More from CV: Feature Detection and Matching

PRO

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test results

Sign in to run your code against the test cases.