Algorithm Search⌘K

Algorithmcore

FAST corner detector

Also called features from accelerated segment test.

Call a pixel a corner when n contiguous pixels of the 16 on a circle around it are all brighter or all darker by a threshold, tested in an order learned by a decision tree.

Time
O(W H n) worstO(W H) average · best
Space
O(W H) extra
Where
H = the image height in pixels; W = the image width in pixels; n = the length of the arc
Properties
deterministicexactheuristicnot rotation invariant responsenot scale invariant
Origin
Edward Rosten, Tom Drummond, 2006

The FAST corner detector (features from accelerated segment test) solves corner detection with comparisons only. It looks at the 16 pixels on a circle of radius 3 around a pixel pp and calls pp a corner when nn contiguous pixels of the circle are all brighter than Ip+tI_p + t or all darker than Ip−tI_p - t. This is the segment test. Unlike the Harris and Shi-Tomasi detectors it computes no gradients and no sums, and most pixels are rejected after two comparisons. Edward Rosten and Tom Drummond made the test fast by learning, with a decision tree, the order in which to read the circle pixels. The cost is O(WH)O(WH) for a W×HW \times H image. The score that ranks the corners for non-maximum suppression is the largest threshold for which the pixel is still a corner. FAST is the detector inside ORB.

In plain words

Draw a small circle of 16 pixels around a pixel. If a long unbroken part of the circle, say 9 pixels in a row, is clearly brighter than the center, or clearly darker, then the center is a corner. On a flat area the circle looks like the center. On a straight edge about half of the circle is brighter and half is the same, and half of 16 is not enough. Only near a corner or a small spot does a long arc differ from the center. The test needs no arithmetic beyond comparisons, and most pixels fail it after a look at two circle pixels. To keep one point per corner, give each corner a score, the largest threshold at which it still passes, and drop corners with a stronger neighbour.

The problem

The input is a gray digital image II with WW columns and HH rows of integer values, an integer threshold t≥1t \ge 1 and an arc length nn with 1≤n≤161 \le n \le 16. A pixel has integer coordinates (u,v)(u, v): uu is the column and goes right, vv is the row and goes down. The circle is the discrete circle of radius 3 with 16 pixels, numbered 1 to 16 clockwise from the top:

(0,−3),(1,−3),(2,−2),(3,−1),(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), (3, 0), (3, 1), (2, 2), (1, 3), (0, 3), (-1, 3), (-2, 2), (-3, 1), (-3, 0), (-3, -1), (-2, -2), (-1, -3).

Pixels 1, 5, 9 and 13 are the top, right, bottom and left. Only the pixels with 3≤u≤W−43 \le u \le W - 4 and 3≤v≤H−43 \le v \le H - 4 are tested, so the circle is inside the image. A circle pixel xx is brighter when I(x)≥Ip+tI(x) \ge I_p + t and darker when I(x)≤Ip−tI(x) \le I_p - t; this follows equation 8 of the 2010 paper. Some implementations use strict inequalities, which for integer images is the same test with t+1t + 1. The pixel pp is a corner when there is a run of nn contiguous circle pixels, with the run allowed to wrap from pixel 16 to pixel 1, that are all brighter or all darker.

The score V(p)V(p) is the largest tt for which pp is still a corner. For integer images it has a closed form. For an arc AA of nn contiguous circle pixels, all pixels of AA are brighter for threshold tt exactly when t≤min⁡x∈A(I(x)−Ip)t \le \min_{x \in A} (I(x) - I_p), and all are darker exactly when t≤min⁡x∈A(Ip−I(x))t \le \min_{x \in A} (I_p - I(x)). So

V(p)=max⁡Amax⁡(min⁡x∈A(I(x)−Ip),  min⁡x∈A(Ip−I(x))),V(p) = \max_{A} \max\Big(\min_{x \in A} \big(I(x) - I_p\big), \; \min_{x \in A} \big(I_p - I(x)\big)\Big),

and pp is a corner for the threshold tt exactly when V(p)≥tV(p) \ge t. The output is the set of corners whose score is not smaller than the score of any corner among their eight neighbours.

The algorithm

  1. FAST(I, t, n) ▷ I is W × H with integer values, t ≥ 1
  2. 1for each pixel p with 3 ≤ u ≤ W - 4 and 3 ≤ v ≤ H - 4 do
  3. 2if n = 12 and fewer than 3 of the pixels 1, 5, 9, 13 are brighter and fewer than 3 are darker then skip p
  4. 3V(p) ← the largest, over the 16 arcs A of n contiguous circle pixels, of max(min over A of I(x) - I_p, min over A of I_p - I(x))
  5. 4if V(p) ≥ t then add p to the candidates C
  6. 5corners ← ∅
  7. 6for each p in C do
  8. 7if V(p) ≥ V(q) for each q in C with q one of the 8 neighbours of p then
  9. 8add p to corners
  10. 9return corners

Line L2 is the high-speed test of the original detector. It is valid only for n=12n = 12: a run of 12 contiguous pixels leaves out a run of 4, and any 4 contiguous pixels hold exactly one of the pixels 1, 5, 9 and 13, so a corner has at least 3 of the four brighter or at least 3 darker. For n=9n = 9 a run can hold only two of them, and the test would reject real corners. Line L3 computes the score, and line L4 is the segment test, since V(p)≥tV(p) \ge t is the same as a run of nn brighter or darker pixels. Lines L5 to L8 are a 3×33 \times 3 non-maximum suppression on the scores, as in Section III-C of the 2010 paper. The test at line L7 is not strict, so a group of neighbours with the same score is kept whole.

A real FAST detector does not run line L3 on every pixel. It first runs the segment test as a learned decision tree that reads one circle pixel at a time and stops as soon as the answer is known, and it computes the score only for the few pixels that pass. The tree changes the speed, not the output.

The learned tree

Each circle pixel xx of pp is in one of three states: darker, similar or brighter. Rosten and Drummond collect the 16 states of every pixel in a set of training images, label each pixel by the segment test, and grow a tree with the ID3 rule: at each node, read the circle pixel whose state gives the most information about the label. They add all 316=430467213^{16} = 43046721 state patterns with a low weight, so the tree computes the segment test exactly and not only on the training images. The tree is then written out as nested if-else code. The order of the questions is tuned to the images, which is the source of the speed. The paper also forces the second question to be the same on every branch, so the first two tests can run on a strip of pixels with vector instructions; most pixels are rejected after these two tests.

Example

Take an 11×1111 \times 11 image with 00 everywhere except a block of 99s at u≥5u \ge 5 and v≥5v \ge 5, with t=1t = 1 and n=9n = 9. At the corner pixel p=(5,5)p = (5, 5) the 16 circle values, from pixel 1 to pixel 16, are

0,0,0,0,9,9,9,9,9,0,0,0,0,0,0,0.0, 0, 0, 0, 9, 9, 9, 9, 9, 0, 0, 0, 0, 0, 0, 0 .

The 11 zeros from pixel 10 around to pixel 4 are one run, all darker than 9−t9 - t. An arc of 9 of them gives min⁡(Ip−I(x))=9\min(I_p - I(x)) = 9, so V(5,5)=9V(5, 5) = 9. A pixel just outside the block, such as (4,4)(4, 4), sees only 3 bright pixels on its circle and fails.

The corners are the six pixels (5,5)(5, 5), (6,5)(6, 5), (7,5)(7, 5), (5,6)(5, 6), (6,6)(6, 6) and (5,7)(5, 7), all with score 9. Since the scores are equal, the suppression keeps all six; a strict test would drop all six. For n=12n = 12 there are no corners at all: a right angle leaves only 11 darker pixels on the circle. This is one reason why FAST-9 replaced FAST-12. For t=10t = 10 there are no corners either, since no score is above 9.

Correctness

The output is the set defined in The problem. The proof in proofs/correctness.md shows three facts:

  • the closed form of V(p)V(p) is the largest threshold for which pp passes the segment test, and the test passes for tt exactly when V(p)≥tV(p) \ge t;
  • the high-speed test of line L2 never rejects a corner when n=12n = 12, so it changes the speed and not the output;
  • lines L5 to L9 return exactly the candidates that are not smaller than any candidate neighbour.

For n=9n = 9 the second fact fails: the circle with pixels 2 to 10 darker and the rest equal to the center is a corner, but only two of the pixels 1, 5, 9 and 13 are darker. That a FAST corner is a good corner for a given task is not a theorem; the 2010 paper measures it as repeatability on image sequences.

Proof: Correctness of the FAST corner detectorfull

Fix an integer image II, a pixel pp that is at least 3 pixels from each border, and an arc length nn with 1≤n≤161 \le n \le 16. Number the circle pixels x0,…,x15x_0, \dots, x_{15} in the order of the page, and let an arc be a set As={x(s+k) mod 16:0≤k<n}A_s = \{x_{(s + k) \bmod 16} : 0 \le k < n\} for 0≤s<160 \le s < 16. For a threshold t≥1t \ge 1, pp passes the segment test when some arc has all its pixels brighter (I(x)≥Ip+tI(x) \ge I_p + t) or all darker (I(x)≤Ip−tI(x) \le I_p - t).

Lemma 1 (the score). Let b(A)=min⁡x∈A(I(x)−Ip)b(A) = \min_{x \in A} (I(x) - I_p), d(A)=min⁡x∈A(Ip−I(x))d(A) = \min_{x \in A} (I_p - I(x)) and V=max⁡smax⁡(b(As),d(As))V = \max_s \max(b(A_s), d(A_s)). For each integer tt, pp passes the segment test with threshold tt if and only if V≥tV \ge t. So VV is the largest threshold for which pp passes, and the set of thresholds for which it passes is {t:t≤V}\{t : t \le V\}.

Proof. All pixels of AA are brighter for tt exactly when I(x)−Ip≥tI(x) - I_p \ge t for each x∈Ax \in A, that is when b(A)≥tb(A) \ge t. In the same way all are darker exactly when d(A)≥td(A) \ge t. So pp passes exactly when b(As)≥tb(A_s) \ge t or d(As)≥td(A_s) \ge t for some ss, which is when the largest of these 3232 numbers, VV, is at least tt. Since VV is an integer, the passing thresholds are the integers up to VV, and the largest is VV. □\square

Lemma 2 (the high-speed test for n=12n = 12). If n=12n = 12 and pp passes the segment test for tt, then at least 3 of x0,x4,x8,x12x_0, x_4, x_8, x_{12} are brighter, or at least 3 are darker.

Proof. Let AsA_s be an arc of 12 pixels that are all brighter (the darker case is the same). Its complement on the circle is the arc of the 4 positions s+12,s+13,s+14,s+15s + 12, s + 13, s + 14, s + 15 modulo 16. Four consecutive integers hold exactly one multiple of 4, so the complement holds exactly one of the positions 0,4,8,120, 4, 8, 12, and AsA_s holds the other three. All pixels of AsA_s are brighter. □\square

So line L2 skips only pixels that would fail the test of line L4, and the set of candidates is the same with or without it. For n<12n < 12 the complement has 16−n≥516 - n \ge 5 positions and can hold two of the four, so the lemma fails; the page gives an example with n=9n = 9.

Theorem. FAST returns the set of pixels pp that pass the segment test for tt and whose score V(p)V(p) is not smaller than the score of any passing pixel among their eight neighbours.

Proof. Line L1 visits each testable pixel once. By Lemma 2, line L2 skips only pixels that fail the segment test. Line L3 computes V(p)V(p) as in Lemma 1, and by Lemma 1 line L4 adds pp to CC exactly when pp passes. So after the first loop CC is the set of passing pixels, each with its score. Lines L6 to L8 add p∈Cp \in C to the output exactly when V(p)≥V(q)V(p) \ge V(q) for each q∈Cq \in C among its eight neighbours, and no line removes a pixel. Line L9 returns this set. □\square

Remark (rotation by 90°90°). The map (du,dv)↦(−dv,du)(du, dv) \mapsto (-dv, du), which is the rotation that sends pixel (u,v)(u, v) of a W×HW \times H image to pixel (H−1−v,u)(H - 1 - v, u) of the rotated image, sends xix_i to x(i+4) mod 16x_{(i + 4) \bmod 16}; this can be checked on the 16 offsets. A cyclic shift maps arcs to arcs, so the score of each pixel is the same as the score of its image, and the output of the rotated image is the rotated output. ■\blacksquare

Complexity

The model is the word RAM with integer pixels.

  • Line L2 reads 4 pixels, and line L3 reads 16 pixels and takes the minimum over 16 arcs of nn pixels, which is O(n)O(n) time per pixel with the direct loop, or O(1)O(1) with a sliding minimum over the circle. Over WHWH pixels this is O(WHn)O(WHn), which is O(WH)O(WH) since n≤16n \le 16.
  • Lines L6 and L7 cost O(1)O(1) per candidate.
  • A hash set or a W×HW \times H table of scores takes O(WH)O(WH) extra space.

The decision tree reads at most 16 pixels per pixel and, for most pixels of typical images, two. The output does not depend on the tree, only the time does.

Properties

  • Comparisons only. The segment test uses comparisons with Ip±tI_p \pm t, so it suits 8-bit images and simple hardware.
  • Offset invariant. Adding a constant to the image changes nothing. A gain changes which pixels pass for a fixed tt, since tt is absolute.
  • Rotation. The circle maps to itself under a rotation by 90°90° (a cyclic shift by 4 positions) and under a mirror, so the detector commutes with these. For other angles the discrete circle is only close to rotation invariant.
  • Not scale invariant. The circle has a fixed radius of 3 pixels. ORB and BRISK run FAST on each level of an image pyramid.
  • Clusters. The test is true for several adjacent pixels at one corner, as the example shows. The suppression thins them only when the scores differ.
  • Spots and lines. A single bright pixel passes for any nn, and a thin line passes for small nn. The segment test answers "a long arc differs from the center", which includes more than corners.

Variants and improvements

  • FAST-12 and FAST-9. The original test used n=12n = 12 because of the high-speed test. The 2010 paper reports that n=9n = 9 gives the best repeatability.
  • FAST-ER. The 2010 paper also learns the shape of the test itself, with a larger set of pixels around pp, by simulated annealing that maximizes repeatability. The result is slower than FAST-9 and more repeatable.
  • AGAST. Mair and others build the tree adaptively, so it does not need training on images of the target domain.
  • Scores. Other scores are the sum of the absolute differences over the arc, or a Harris response computed at each FAST corner; ORB uses the Harris response to rank the corners.
  • Pyramids. Detect on each level of an image pyramid to cover scales, as in ORB and BRISK.

When to use it

Use it when time is short: real-time tracking, visual odometry, SLAM on embedded processors, or a first stage that proposes candidates for a slower descriptor. Pair it with a pyramid for scale and with a Harris or Shi-Tomasi score if the corner quality matters. For precise localization or for matching under large changes of scale or viewpoint, use a detector with scale selection such as the DoG detector.

Pitfalls

  • High-speed test with n≠12n \ne 12. The test with pixels 1, 5, 9 and 13 is only valid for n=12n = 12. For n=9n = 9 it rejects true corners, as the example in Correctness shows.
  • Threshold zero. With t=0t = 0 and the non-strict inequalities, a circle pixel equal to the center is both brighter and darker, and every pixel is a corner. Use t≥1t \ge 1.
  • Wrap around. A run can cross from pixel 16 to pixel 1. Code that scans the circle once from pixel 1 misses those runs.
  • Border. The circle needs 3 pixels on each side. Pixels within 3 of the border cannot be tested.
  • Plateaus in the suppression. Equal scores on neighbours, as in the example, are kept by a test with ≥\ge and all dropped by a test with >>. Neither is right in general; break ties by position if one point per corner is needed.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

fast_corner_detector.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/fast-corner-detector/. The authors are listed in prov/99A606.jsonl.

"""FAST corner detector (features from accelerated segment test).

An image is a list of H rows of W integers; pixel (u, v) is img[v][u], with
u the column (to the right) and v the row (down). The test reads the 16
pixels of a circle of radius 3 around p, numbered 1 to 16 clockwise from the
top. A pixel x of the circle is brighter when I(x) >= I(p) + t and darker
when I(x) <= I(p) - t (equation 8 of Rosten, Porter and Drummond, 2010).
p is a corner when n contiguous circle pixels are all brighter or all darker.

The score V(p) is the largest t for which p is still a corner. For integer
images it has the closed form

    V(p) = max over the 16 arcs A of n contiguous circle pixels of
           max(min over x in A of (I(x) - I(p)), min over x in A of (I(p) - I(x))),

and p is a corner for the threshold t >= 1 exactly when V(p) >= t.
Only pixels with 3 <= u <= W - 4 and 3 <= v <= H - 4 are tested.
"""

from typing import Dict, List, Sequence, Tuple

Image = Sequence[Sequence[int]]

# Circle offsets (du, dv) for the pixels 1 to 16, clockwise from the top.
CIRCLE: Tuple[Tuple[int, int], ...] = (
    (0, -3), (1, -3), (2, -2), (3, -1), (3, 0), (3, 1), (2, 2), (1, 3),
    (0, 3), (-1, 3), (-2, 2), (-3, 1), (-3, 0), (-3, -1), (-2, -2), (-1, -3),
)
COMPASS = (0, 4, 8, 12)  # the pixels 1, 5, 9 and 13


def ring(img: Image, u: int, v: int) -> List[int]:
    """The 16 circle values around (u, v), in the order of CIRCLE."""
    return [img[v + dv][u + du] for du, dv in CIRCLE]


def high_speed_reject(center: int, values: List[int], t: int) -> bool:
    """True when fewer than 3 of the pixels 1, 5, 9, 13 are brighter and fewer than 3 are darker.

    Valid for n = 12 only: then a rejected pixel is never a corner.
    """
    bright = sum(1 for i in COMPASS if values[i] >= center + t)
    dark = sum(1 for i in COMPASS if values[i] <= center - t)
    return bright < 3 and dark < 3


def fast_score(center: int, values: List[int], n: int) -> int:
    """V(p): the largest t for which some arc of n contiguous pixels is all brighter or all darker."""
    best = None
    for s in range(16):
        arc = [values[(s + k) % 16] for k in range(n)]
        up = min(x - center for x in arc)
        down = min(center - x for x in arc)
        cand = up if up > down else down
        if best is None or cand > best:
            best = cand
    return best


def fast_scores(img: Image, t: int = 20, n: int = 9, high_speed: bool = True) -> Dict[Tuple[int, int], int]:
    """Return {(u, v): V} for the pixels that pass the segment test with threshold t."""
    h, w = len(img), len(img[0])
    found: Dict[Tuple[int, int], int] = {}
    for v in range(3, h - 3):  # @line L1
        for u in range(3, w - 3):
            c = img[v][u]
            vals = ring(img, u, v)
            if high_speed and n == 12 and high_speed_reject(c, vals, t):  # @line L2
                continue
            score = fast_score(c, vals, n)  # @line L3
            if score >= t:  # @line L4
                found[(u, v)] = score
    return found


def fast_corners(img: Image, t: int = 20, n: int = 9, nms: bool = True, high_speed: bool = True) -> List[Tuple[int, int]]:
    """Return the corners (u, v), sorted by v then u.

    Precondition: img is a non-empty rectangular list of integer rows,
    t >= 1 and 1 <= n <= 16. With nms, a corner is kept when its score is
    not smaller than the score of any detected corner among its 8 neighbours.
    """
    scores = fast_scores(img, t, n, high_speed)
    keys = sorted(scores, key=lambda p: (p[1], p[0]))
    if not nms:
        return keys
    out: List[Tuple[int, int]] = []  # @line L5
    for u, v in keys:  # @line L6
        s = scores[(u, v)]
        if all(scores.get((u + du, v + dv), s) <= s for du in (-1, 0, 1) for dv in (-1, 0, 1)):  # @line L7
            out.append((u, v))  # @line L8
    return out  # @line L9
test_fast_corner_detector.py 139 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/fast-corner-detector/. The authors are listed in prov/99A606.jsonl.

import random

from fast_corner_detector import CIRCLE, COMPASS, fast_corners, fast_scores, high_speed_reject, ring


def segment_test(img, u, v, t, n):
    """Brute force: is there a run of n circle pixels, all brighter or all darker?"""
    c = img[v][u]
    vals = [img[v + dv][u + du] for du, dv in CIRCLE]
    for start in range(16):
        run = [vals[(start + k) % 16] for k in range(n)]
        if all(x >= c + t for x in run) or all(x <= c - t for x in run):
            return True
    return False


def oracle(img, t, n):
    """Score by a linear scan over thresholds, then 3 x 3 suppression."""
    h, w = len(img), len(img[0])
    scores = {}
    for v in range(3, h - 3):
        for u in range(3, w - 3):
            if segment_test(img, u, v, t, n):
                s = t
                while segment_test(img, u, v, s + 1, n):
                    s += 1
                scores[(u, v)] = s
    keep = []
    for (u, v), s in scores.items():
        if all(scores.get((u + a, v + b), -1) <= s for a in (-1, 0, 1) for b in (-1, 0, 1)):
            keep.append((u, v))
    return sorted(keep, key=lambda p: (p[1], p[0])), scores


def block():
    return [[9 if (u >= 5 and v >= 5) else 0 for u in range(11)] for v in range(11)]


def test_circle_is_a_bresenham_circle_of_radius_3():
    assert len(set(CIRCLE)) == 16
    assert all(8 <= du * du + dv * dv <= 10 or du * dv == 0 for du, dv in CIRCLE)
    assert all(max(abs(du), abs(dv)) == 3 or (abs(du), abs(dv)) == (2, 2) for du, dv in CIRCLE)
    # Consecutive pixels touch, so the circle is a closed 8-connected loop.
    for i in range(16):
        (a, b), (c, d) = CIRCLE[i], CIRCLE[(i + 1) % 16]
        assert max(abs(a - c), abs(b - d)) == 1
    assert [CIRCLE[i] for i in COMPASS] == [(0, -3), (3, 0), (0, 3), (-3, 0)]


def test_worked_example_block_corner():
    img = block()
    assert ring(img, 5, 5) == [0, 0, 0, 0, 9, 9, 9, 9, 9, 0, 0, 0, 0, 0, 0, 0]
    scores = fast_scores(img, 1, 9)
    assert scores == {(5, 5): 9, (6, 5): 9, (7, 5): 9, (5, 6): 9, (6, 6): 9, (5, 7): 9}
    assert fast_corners(img, 1, 9) == [(5, 5), (6, 5), (7, 5), (5, 6), (6, 6), (5, 7)]
    # A right-angle corner leaves only 11 dark pixels on the circle, so FAST-12 misses it.
    assert fast_scores(img, 1, 12) == {}
    assert fast_scores(img, 10, 9) == {}


def test_flat_image_and_small_image():
    assert fast_corners([[4] * 9 for _ in range(9)], 1, 9) == []
    assert fast_corners([[1, 2, 3, 4, 5, 6]] * 6, 1, 9) == []


def test_single_bright_pixel():
    img = [[0] * 7 for _ in range(7)]
    img[3][3] = 50
    assert fast_scores(img, 1, 16) == {(3, 3): 50}
    assert fast_corners(img, 50, 9) == [(3, 3)]
    assert fast_corners(img, 51, 9) == []


def test_high_speed_test_is_exact_for_n_12():
    # For every set of brighter pixels on the circle: a run of 12 implies 3 of the 4 compass pixels.
    for mask in range(1 << 16):
        bits = [(mask >> i) & 1 for i in range(16)]
        run12 = any(all(bits[(s + k) % 16] for k in range(12)) for s in range(16))
        if run12:
            assert sum(bits[i] for i in COMPASS) >= 3


def test_high_speed_test_is_wrong_for_n_9():
    # A dark run of 9 that holds only 2 compass pixels: pixels 2 to 10.
    vals = [10] * 16
    for i in range(1, 10):
        vals[i] = 0
    assert sum(1 for i in COMPASS if vals[i] <= 10 - 5) == 2
    assert high_speed_reject(10, vals, 5)
    img = [[10] * 7 for _ in range(7)]
    for (du, dv), x in zip(CIRCLE, vals):
        img[3 + dv][3 + du] = x
    assert segment_test(img, 3, 3, 5, 9)
    assert fast_scores(img, 5, 9) == {(3, 3): 10}


def test_high_speed_flag_does_not_change_output():
    rng = random.Random(12)
    for _ in range(80):
        img = [[rng.choice([0, 0, 5, 9, 9]) for _ in range(9)] for _ in range(9)]
        assert fast_scores(img, 3, 12, True) == fast_scores(img, 3, 12, False)


def test_random_against_oracle():
    rng = random.Random(2006)
    for _ in range(600):
        w, h = rng.randint(7, 10), rng.randint(7, 10)
        img = [[rng.randint(0, 6) for _ in range(w)] for _ in range(h)]
        if rng.random() < 0.5:
            # Plant a bright or dark blob so that corners occur often.
            cu, cv = rng.randint(3, w - 4), rng.randint(3, h - 4)
            img[cv][cu] = rng.choice([0, 12])
        t = rng.randint(1, 4)
        n = rng.choice([9, 10, 11, 12])
        want, scores = oracle(img, t, n)
        assert fast_scores(img, t, n) == scores
        assert fast_corners(img, t, n) == want


def test_rotation_by_90_degrees():
    rng = random.Random(77)
    for _ in range(60):
        h, w = 9, 10
        img = [[rng.randint(0, 9) for _ in range(w)] for _ in range(h)]
        # rot[i][j] = img[h - 1 - j][i]: pixel (u, v) of img goes to (h - 1 - v, u).
        rot = [[img[h - 1 - j][i] for j in range(h)] for i in range(w)]
        a = fast_scores(img, 2, 9)
        b = fast_scores(rot, 2, 9)
        assert {(h - 1 - v, u): s for (u, v), s in a.items()} == b


def test_offset_invariance():
    rng = random.Random(3)
    for _ in range(40):
        img = [[rng.randint(0, 9) for _ in range(9)] for _ in range(9)]
        assert fast_scores([[x + 100 for x in r] for r in img], 2, 9) == fast_scores(img, 2, 9)

History

Rosten and Drummond first used the segment test with n=12n = 12 and the high-speed test in a system for real-time tracking. At ECCV 2006 they presented the learned version: a decision tree, grown by ID3 from the states of the circle pixels, that computes the segment test with few comparisons. In the 2010 journal version, with Reid Porter, they extended the evaluation, chose n=9n = 9, defined the score as the largest threshold and introduced FAST-ER. FAST became the standard fast detector, and ORB (2011) made it a part of a complete feature pipeline.

References

  1. Edward Rosten and Tom Drummond, Machine learning for high-speed corner detection, European Conference on Computer Vision (ECCV), LNCS 3951, 2006, pages 430-443, the whole paper (the segment test, the learned decision tree and the non-maximal suppression)
  2. Edward Rosten, Reid Porter and Tom Drummond, Faster and better, a machine learning approach to corner detection, IEEE Transactions on Pattern Analysis and Machine Intelligence 32(1), 105-119, 2010 (arXiv 0810.2434), Section III-A (the segment test and the high-speed test), equation 8 (the three states), Section III-B (the ID3 tree and the 3^16 configurations), Section III-C (the score and the 3 x 3 suppression)
  3. Richard Szeliski, Computer Vision, Algorithms and Applications, second edition, Springer, 2022, Chapter 7, Section 7.1.1, Feature detectors

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.average
  • a full proof of time.best
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example