Algorithm Search⌘K

Algorithmintro

Moravec corner detector

Also called Moravec interest operator.

Score each pixel by the smallest sum of squared differences between its window and the window shifted by one pixel in four directions, and keep the local maxima.

Time
O(W H r^2) worst · average · best
Space
Θ(W H) extra
Where
H = the image height in pixels; W = the image width in pixels; r = the radius of the window in pixels
Properties
deterministicexactheuristicnot rotation invariant responsenot scale invariant
Origin
Hans Moravec, 1980

The Moravec corner detector, also called the Moravec interest operator, is the first widely used method for corner detection. For each pixel it compares a small window with the same window moved by one pixel in four directions, horizontal, vertical and the two diagonals. It sums the squared differences for each direction and takes the smallest of the four sums as the score, so a pixel scores high only when the image changes in every one of the four directions. It keeps the pixels whose score is a local maximum above a threshold. The cost is O(WHr2)O(WHr^2) for a W×HW \times H image and a window of radius rr. The Harris corner detector replaces the four discrete shifts by a quadratic form in the gradients, and the Shi-Tomasi detector by the smaller eigenvalue of that form; both are fixes of the faults of this operator that are shown below.

In plain words

Put a small square window on the image and move it one pixel to the right. Add up how much each pixel under the window changed, squared. Do the same for a move down and for the two diagonal moves. On a flat area none of the four moves changes anything. On a straight edge the move along the edge changes nothing, so the smallest of the four totals is zero. Only on a corner or on a spot does every move change the window. So the score of a pixel is the smallest of its four totals. A pixel is a corner if its score is above a threshold and no pixel near it has a higher score. The method is simple and uses only integer additions and products.

The problem

The input is a gray digital image II with WW columns and HH rows of integer values. A pixel has integer coordinates (u,v)(u, v): uu is the column and goes right, vv is the row and goes down, and the origin is the top left pixel. The window has radius rr, so it holds (2r+1)2(2r + 1)^2 pixels. For a shift (a,b)(a, b) the change of the window at (u,v)(u, v) is

Eab(u,v)=∑j=−rr∑i=−rr(I(u+i+a,v+j+b)−I(u+i,v+j))2.E_{ab}(u, v) = \sum_{j=-r}^{r} \sum_{i=-r}^{r} \big(I(u + i + a, v + j + b) - I(u + i, v + j)\big)^2 .

The response is the minimum over four shifts,

C(u,v)=min⁡(a,b)∈SEab(u,v),S={(1,0),(0,1),(1,1),(1,−1)}.C(u, v) = \min_{(a, b) \in S} E_{ab}(u, v), \qquad S = \{(1, 0), (0, 1), (1, 1), (1, -1)\}.

This page uses no border rule: CC is defined only where each read is inside the image, that is for r+1≤u≤W−r−2r + 1 \le u \le W - r - 2 and r+1≤v≤H−r−2r + 1 \le v \le H - r - 2. The output is the set of defined pixels with C>τC > \tau that are not smaller than CC at any defined pixel within a Chebyshev distance mm. As for every corner detector, "corner" here means the points that this response selects; the problem page explains why there is no single correct answer.

Moravec's thesis states the operator as the sum of squares of the differences of adjacent pixels in each of four directions over the window. The shift form above, which Harris and Stephens use when they analyze the operator, counts the same kind of pairs; the two forms differ only in which pairs at the border of the window they include. Some texts use all eight unit shifts. The opposite shift adds nothing new in the limit of a large window, since E−a,−b(u,v)=Eab(u−a,v−b)E_{-a,-b}(u, v) = E_{ab}(u - a, v - b): it is the same sum, taken at the neighbouring pixel.

The algorithm

  1. MORAVEC(I, r, τ, m) ▷ I is W × H with integer values, τ ≥ 0, m ≥ 1
  2. 1S ← {(1, 0), (0, 1), (1, 1), (1, -1)}
  3. 2for each pixel (u, v) with r + 1 ≤ u ≤ W - r - 2 and r + 1 ≤ v ≤ H - r - 2 do
  4. 3C(u, v) ← min over (a, b) ∈ S of E_ab(u, v)
  5. 4corners ← ∅
  6. 5for each pixel (u, v) where C is defined and C(u, v) > τ do
  7. 6if C(u, v) ≥ C(u', v') for each defined (u', v') with |u' - u| ≤ m and |v' - v| ≤ m then
  8. 7add (u, v) to corners
  9. 8return corners

Line L1 fixes the four directions: right, down, and the two diagonals. Lines L2 and L3 compute the response at every pixel where the shifted window stays inside the image. Each EabE_{ab} is a sum of (2r+1)2(2r + 1)^2 squared integer differences. Lines L4 to L7 keep the pixels above the threshold that are local maxima of CC. The test at line L6 is not strict, so two equal neighbours are both kept. Moravec spaced his windows half a window apart and kept a window when its score was the largest of the 25 windows that overlap or touch it; this page uses every pixel and the neighbourhood of radius mm, which is the usual dense form.

Example

Take the 8×88 \times 8 image with 00 everywhere except a block of 99s at u≥4u \ge 4 and v≥4v \ge 4. The block has one corner, at (4,4)(4, 4), and two edges, along the row v=4v = 4 and the column u=4u = 4. With r=1r = 1, CC is defined for 2≤u,v≤52 \le u, v \le 5. The four sums at some pixels are:

pixel kind E1,0E_{1,0} E0,1E_{0,1} E1,1E_{1,1} E1,−1E_{1,-1} CC
(4,4)(4, 4) corner 162 162 405 243 162
(3,3)(3, 3) next to the corner 81 81 243 81 81
(5,4)(5, 4) on the top edge 0 243 243 243 0
(4,5)(4, 5) on the left edge 243 0 243 324 0

At (4,4)(4, 4) the window covers 3≤u,v≤53 \le u, v \le 5, and four of its pixels are 99. The shift (1,0)(1, 0) changes the two pixels (3,4)(3, 4) and (3,5)(3, 5) from 00 to 99, so E1,0=2⋅81=162E_{1,0} = 2 \cdot 81 = 162. At (5,4)(5, 4) the shift along the edge, (1,0)(1, 0), changes nothing, so C=0C = 0. The full table of CC for 2≤u,v≤52 \le u, v \le 5 is 00 except for C(3,3)=C(4,3)=C(3,4)=81C(3, 3) = C(4, 3) = C(3, 4) = 81 and C(4,4)=162C(4, 4) = 162. With τ=0\tau = 0 and m=1m = 1 the detector returns one corner, (4,4)(4, 4).

Now take a 10×1010 \times 10 image with I=9I = 9 where 2v≥u+32v \ge u + 3 and 00 elsewhere. This is a straight edge with a slope of 1/21/2, at about 27°27°, which is not one of the four directions. At (5,4)(5, 4) the sums are 8181, 243243, 162162 and 324324, so C=81C = 81. Every pixel of the defined area that touches the edge has C=81C = 81, and with τ=0\tau = 0 and m=1m = 1 the detector returns 17 "corners", all on the edge. A vertical edge or an edge at 45°45° gives C=0C = 0 everywhere, because one of the four shifts runs along it.

Correctness

The detector computes exactly the response it defines. Lines L2 and L3 visit each pixel of the defined area once and set C(u,v)C(u, v) to the minimum of the four sums. Lines L5 to L7 add a pixel exactly when it passes the threshold and the neighbourhood test, and no line removes a pixel. So the output is the set described in The problem. The full proof is in proofs/correctness.md. It also proves the facts that justify the response:

  • C(u,v)=0C(u, v) = 0 when the window lies in a region where II is constant along one of the four directions. So a straight edge along a direction of SS gives no response.
  • On a window where II is constant, all four sums are 00.
  • An offset I+cI + c gives the same CC, and a gain gIgI gives g2Cg^2 C; with τ=0\tau = 0 the output does not change.

Whether a returned pixel is a corner for a human is not a theorem. The slanted edge above shows that the operator reports edges at angles between the four directions.

Proof: Correctness of the Moravec corner detectorfull

We prove that MORAVEC returns exactly the set defined in The problem, and we prove the three facts about the response that the page states.

Setting. II is a W×HW \times H image with integer values, r≥0r \ge 0, m≥1m \ge 1 and τ≥0\tau \ge 0. Let DD be the set of pixels with r+1≤u≤W−r−2r + 1 \le u \le W - r - 2 and r+1≤v≤H−r−2r + 1 \le v \le H - r - 2. The target output is

T={(u,v)∈D:C(u,v)>τ and C(u,v)≥C(u′,v′) for each (u′,v′)∈D with ∣u′−u∣≤m,∣v′−v∣≤m}.T = \{(u, v) \in D : C(u, v) > \tau \text{ and } C(u, v) \ge C(u', v') \text{ for each } (u', v') \in D \text{ with } |u' - u| \le m, |v' - v| \le m\}.

Lemma 1 (the reads are in the image). For (u,v)∈D(u, v) \in D, (a,b)∈S(a, b) \in S and ∣i∣,∣j∣≤r|i|, |j| \le r, both (u+i,v+j)(u + i, v + j) and (u+i+a,v+j+b)(u + i + a, v + j + b) are pixels of II.

Proof. Each of aa and bb is in {−1,0,1}\{-1, 0, 1\}. So u+i+a≥(r+1)−r−1=0u + i + a \ge (r + 1) - r - 1 = 0 and u+i+a≤(W−r−2)+r+1=W−1u + i + a \le (W - r - 2) + r + 1 = W - 1. The same bounds hold for u+iu + i, and the same argument with HH holds for the row. □\square

Lemma 2 (the table CC). After lines L1 to L3, CC is defined exactly on DD, and for each (u,v)∈D(u, v) \in D it holds min⁡(a,b)∈SEab(u,v)\min_{(a, b) \in S} E_{ab}(u, v).

Proof. Line L2 visits each pixel of DD once and no other pixel. By Lemma 1, each sum Eab(u,v)E_{ab}(u, v) reads only pixels of II, so it is a well defined integer. Line L3 stores the minimum of the four sums for the set SS of line L1, and no later line writes to CC. □\square

Theorem (output). MORAVEC returns TT.

Proof. By Lemma 2, line L5 visits exactly the pixels (u,v)∈D(u, v) \in D with C(u,v)>τC(u, v) > \tau, each once. For such a pixel, line L6 tests C(u,v)≥C(u′,v′)C(u, v) \ge C(u', v') for each defined (u′,v′)(u', v') in the square of radius mm. The pixel (u′,v′)=(u,v)(u', v') = (u, v) passes this test trivially, so the test is true exactly when the second condition in the definition of TT holds. Line L7 adds the pixel exactly when the test is true. Lines L4 to L7 only add to the set, so after the loop the set holds each pixel of TT and no other pixel, and line L8 returns it. □\square

Proposition 1 (an edge along a direction of SS). Let (u,v)∈D(u, v) \in D and (a,b)∈S(a, b) \in S. If I(p+(a,b))=I(p)I(p + (a, b)) = I(p) for each pixel pp of the window at (u,v)(u, v), then C(u,v)=0C(u, v) = 0. In particular, a window that lies in a region where II is constant gives C=0C = 0.

Proof. Each term of Eab(u,v)E_{ab}(u, v) is (I(p+(a,b))−I(p))2=0(I(p + (a, b)) - I(p))^2 = 0, so Eab(u,v)=0E_{ab}(u, v) = 0. Each EE is a sum of squares and so is at least 00. The minimum of four numbers that are at least 00, one of which is 00, is 00. If II is constant on the window and its shifted copies, the hypothesis holds for each shift. □\square

Proposition 2 (offset and gain). For an integer cc and an integer gg, let C′C' be the response of gI+cgI + c. Then C′(u,v)=g2C(u,v)C'(u, v) = g^2 C(u, v) for each (u,v)∈D(u, v) \in D. If g≠0g \ne 0 and τ=0\tau = 0, MORAVEC returns the same set for gI+cgI + c as for II.

Proof. Each difference becomes (gI(q)+c)−(gI(p)+c)=g(I(q)−I(p))(gI(q) + c) - (gI(p) + c) = g(I(q) - I(p)), so each squared difference, each sum EabE_{ab} and so the minimum CC is multiplied by g2≥0g^2 \ge 0. Multiplying by g2>0g^2 > 0 keeps every inequality C(u,v)≥C(u′,v′)C(u, v) \ge C(u', v') and keeps C(u,v)>0C(u, v) > 0, and the set DD depends only on WW, HH and rr. So by the Theorem the two outputs are the same set. □\square

Proposition 3 (the opposite shift). For a shift s=(a,b)s = (a, b) and a pixel pp such that both sides read only pixels of II, E−a,−b(p)=Eab(p−s)E_{-a,-b}(p) = E_{ab}(p - s).

Proof. Write NN for the set of offsets (i,j)(i, j) with ∣i∣,∣j∣≤r|i|, |j| \le r. Then E−a,−b(p)=∑n∈N(I(p+n−s)−I(p+n))2E_{-a,-b}(p) = \sum_{n \in N} (I(p + n - s) - I(p + n))^2. Put q=p−sq = p - s. The term for nn is (I(q+n)−I(q+n+s))2=(I(q+n+s)−I(q+n))2(I(q + n) - I(q + n + s))^2 = (I(q + n + s) - I(q + n))^2, which is the term for nn of Eab(q)E_{ab}(q). Summing over NN gives the claim. □\square

So the minimum over the eight unit shifts at pp is the minimum of the four sums at pp and of the four sums Eab(p−(a,b))E_{ab}(p - (a, b)) at the neighbours, which is the statement on the page about the eight-shift variant. ■\blacksquare

Complexity

The model is the word RAM. Let the pixels be integers of bb bits. Each squared difference has at most 2b2b bits, and a sum of (2r+1)2(2r + 1)^2 of them has at most 2b+2⌈log⁡2(2r+1)⌉2b + 2\lceil \log_2(2r + 1) \rceil bits, so it fits in one word for 8-bit images and any window that fits in the image.

  • Lines L2 and L3 compute 4 sums of (2r+1)2(2r + 1)^2 terms at each of at most WHWH pixels: O(WHr2)O(WHr^2) time.
  • Lines L5 to L7 compare each pixel with at most (2m+1)2−1(2m + 1)^2 - 1 neighbours: O(WHm2)O(WHm^2) time, which is O(WH)O(WH) for a fixed mm.
  • The table CC takes Θ(WH)\Theta(WH) extra space.

The total is O(WHr2)O(WHr^2) for a fixed mm, in every case. For each shift, the squared differences (I(p+s)−I(p))2(I(p + s) - I(p))^2 form one image, and a box sum over it can use an integral image. Then each EabE_{ab} costs O(1)O(1) per pixel and the whole response costs O(WH)O(WH) for any rr.

Properties

  • Not isotropic. The response looks only in four directions. An edge at an angle between them gets a positive score, as the example shows. This is the first fault that Harris and Stephens list.
  • Noisy. The square window weighs all pixels the same, so a pixel that enters or leaves the window changes the score by a jump. Harris and Stephens use a Gaussian window instead.
  • Edges and noise. The minimum of four sums is large on any pixel where all four shifts change the window, which also happens on noisy edges and on single noisy pixels.
  • Gain and offset. CC does not change under an offset and is multiplied by g2g^2 under a gain gg. A fixed threshold τ>0\tau > 0 therefore depends on the contrast.
  • Not scale invariant. The window and the shift are one pixel in size, so a blurred corner or a corner seen from far away gives a different response.
  • Exact integer arithmetic. No division and no square root is needed.

Variants and improvements

  • Harris and Stephens. Expand EabE_{ab} to first order in the shift. Then E(a,b)≈(a,b)M(a,b)TE(a, b) \approx (a, b) M (a, b)^{\mathsf T} with the structure tensor MM, and every direction is covered at once. This is the Harris corner detector.
  • Smallest eigenvalue. Take the smallest value of the quadratic form over unit shifts, which is the smaller eigenvalue of MM. This is the Shi-Tomasi detector.
  • Eight shifts. Take the minimum over the eight unit shifts. By the identity in The problem, this adds the four sums of the neighbours (u−a,v−b)(u - a, v - b), so the response is a little smoother but has the same faults.
  • Sparse windows. Moravec computed the operator on windows spaced half a window apart, on an image reduced in size, to save time on the computers of his day.
  • Segment tests. The FAST detector compares the pixels on a circle with the center and needs no sums of squares.

When to use it

Use it to teach corner detection, or when only integer additions are available and the edges of interest are horizontal, vertical or diagonal. For any other use, the Harris or Shi-Tomasi detector gives a better response at a similar cost, and FAST is faster on 8-bit images.

Pitfalls

  • Reads outside the image. Line L3 reads up to r+1r + 1 pixels away from (u,v)(u, v). A loop over r≤u≤W−r−1r \le u \le W - r - 1, as for a window without a shift, reads outside the image. Use the bounds of line L2, or a border rule.
  • Strict maxima on plateaus. A test C(u,v)>C(u′,v′)C(u, v) > C(u', v') in place of ≥\ge at line L6 drops both pixels of two equal neighbours. On the corner example both forms return (4,4)(4, 4), but on symmetric shapes the strict test can return nothing.
  • Threshold zero on slanted edges. With τ=0\tau = 0 every pixel on an edge between the four directions passes, as in the example. Choose τ\tau above the response of the edges you expect, or use a detector with an isotropic response.
  • Overflow. In 16-bit arithmetic, a 5×55 \times 5 window of 8-bit differences can reach 25⋅2552=162562525 \cdot 255^2 = 1625625, which does not fit. Use 32-bit or 64-bit sums.

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.

moravec_corner_detector.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/moravec-corner-detector/. The authors are listed in prov/S56VW3.jsonl.

"""Moravec corner detector (interest operator) with exact integer arithmetic.

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 window has radius r,
so it holds (2 r + 1)^2 pixels. For a shift (a, b) the change of the window
at (u, v) is

    E_ab(u, v) = sum over |i| <= r, |j| <= r of
                 (I(u + i + a, v + j + b) - I(u + i, v + j))^2,

and the response is C(u, v) = min of E_ab over the four shifts
(1, 0), (0, 1), (1, 1) and (1, -1). C is defined only where every read is
inside the image: r + 1 <= u <= W - r - 2 and r + 1 <= v <= H - r - 2.
A corner is a defined pixel with C > tau that is not smaller than C at any
defined pixel of its (2 m + 1) x (2 m + 1) neighbourhood.

Cost: O(W H r^2) time and O(W H) extra space on a word RAM.
"""

from typing import Dict, List, Sequence, Tuple

Image = Sequence[Sequence[int]]
SHIFTS: Tuple[Tuple[int, int], ...] = ((1, 0), (0, 1), (1, 1), (1, -1))


def shift_change(img: Image, u: int, v: int, a: int, b: int, r: int) -> int:
    """Return E_ab(u, v), the sum of squared differences for the shift (a, b)."""
    total = 0
    for j in range(-r, r + 1):
        row = img[v + j]
        row_s = img[v + j + b]
        for i in range(-r, r + 1):
            d = row_s[u + i + a] - row[u + i]
            total += d * d
    return total


def moravec_response(img: Image, r: int = 1) -> Dict[Tuple[int, int], int]:
    """Return C as a dict from (u, v) to the response, for the defined pixels only."""
    h, w = len(img), len(img[0])
    resp: Dict[Tuple[int, int], int] = {}
    for v in range(r + 1, h - r - 1):  # @line L2
        for u in range(r + 1, w - r - 1):
            resp[(u, v)] = min(shift_change(img, u, v, a, b, r) for a, b in SHIFTS)  # @line L1 @line L3
    return resp


def moravec_corners(img: Image, r: int = 1, tau: int = 0, m: int = 1) -> 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,
    r >= 0, m >= 1 and tau >= 0.
    """
    resp = moravec_response(img, r)
    corners: List[Tuple[int, int]] = []  # @line L4
    for (u, v), c in sorted(resp.items(), key=lambda kv: (kv[0][1], kv[0][0])):
        if c <= tau:  # @line L5
            continue
        ok = True
        for dv in range(-m, m + 1):  # @line L6
            for du in range(-m, m + 1):
                other = resp.get((u + du, v + dv))
                if (du or dv) and other is not None and other > c:
                    ok = False
        if ok:
            corners.append((u, v))  # @line L7
    return corners  # @line L8
test_moravec_corner_detector.py 102 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/moravec-corner-detector/. The authors are listed in prov/S56VW3.jsonl.

import random

from moravec_corner_detector import SHIFTS, moravec_corners, moravec_response, shift_change


def oracle_corners(img, r, tau, m):
    """Brute force: build the four shifted windows as lists and compare them."""
    h, w = len(img), len(img[0])
    defined = {}
    for v in range(h):
        for u in range(w):
            if not (r + 1 <= u <= w - r - 2 and r + 1 <= v <= h - r - 2):
                continue
            best = None
            for a, b in [(1, 0), (0, 1), (1, 1), (1, -1)]:
                win = [img[v + j][u + i] for j in range(-r, r + 1) for i in range(-r, r + 1)]
                moved = [img[v + j + b][u + i + a] for j in range(-r, r + 1) for i in range(-r, r + 1)]
                e = sum((x - y) ** 2 for x, y in zip(win, moved))
                best = e if best is None else min(best, e)
            defined[(u, v)] = best
    out = []
    for (u, v), c in defined.items():
        if c > tau and all(
            defined.get((u + du, v + dv), -1) <= c
            for du in range(-m, m + 1)
            for dv in range(-m, m + 1)
        ):
            out.append((u, v))
    return sorted(out, key=lambda p: (p[1], p[0]))


def corner_image():
    return [[9 if (u >= 4 and v >= 4) else 0 for u in range(8)] for v in range(8)]


def test_worked_example_corner():
    img = corner_image()
    resp = moravec_response(img, 1)
    assert [shift_change(img, 4, 4, a, b, 1) for a, b in SHIFTS] == [162, 162, 405, 243]
    assert resp[(4, 4)] == 162
    assert resp[(3, 3)] == 81 and resp[(4, 3)] == 81 and resp[(3, 4)] == 81
    assert resp[(5, 4)] == 0 and resp[(4, 5)] == 0 and resp[(2, 2)] == 0
    assert moravec_corners(img, 1, 0, 1) == [(4, 4)]


def test_slanted_edge_gives_false_corners():
    img = [[9 if 2 * v >= u + 3 else 0 for u in range(10)] for v in range(10)]
    resp = moravec_response(img, 1)
    assert [shift_change(img, 5, 4, a, b, 1) for a, b in SHIFTS] == [81, 243, 162, 324]
    corners = moravec_corners(img, 1, 0, 1)
    assert len(corners) == 17
    assert all(resp[p] == 81 for p in corners)


def test_straight_edges_give_zero():
    vert = [[5 if u >= 4 else 0 for u in range(9)] for v in range(9)]
    diag = [[5 if u + v >= 8 else 0 for u in range(9)] for v in range(9)]
    for img in (vert, diag):
        assert all(c == 0 for c in moravec_response(img, 1).values())
        assert moravec_corners(img, 1, 0, 1) == []


def test_flat_and_tiny_images():
    assert moravec_corners([[7] * 6 for _ in range(6)], 1, 0, 1) == []
    assert moravec_response([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 1) == {}
    assert moravec_corners([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 1, 0, 1) == []


def test_random_against_oracle():
    rng = random.Random(1980)
    for _ in range(600):
        w, h = rng.randint(4, 8), rng.randint(4, 8)
        img = [[rng.randint(0, 3) for _ in range(w)] for _ in range(h)]
        r = rng.choice([0, 1])
        m = rng.choice([1, 2])
        tau = rng.choice([0, 2, 5])
        assert moravec_corners(img, r, tau, m) == oracle_corners(img, r, tau, m)


def test_offset_and_gain():
    rng = random.Random(7)
    for _ in range(50):
        img = [[rng.randint(0, 20) for _ in range(9)] for _ in range(9)]
        base = moravec_response(img, 1)
        shifted = moravec_response([[x + 100 for x in row] for row in img], 1)
        scaled = moravec_response([[3 * x for x in row] for row in img], 1)
        assert shifted == base
        assert all(scaled[p] == 9 * base[p] for p in base)
        assert moravec_corners([[3 * x for x in row] for row in img]) == moravec_corners(img)


def test_opposite_shift_identity():
    # E for the shift -s at p equals E for the shift s at p - s.
    rng = random.Random(11)
    img = [[rng.randint(0, 50) for _ in range(10)] for _ in range(10)]
    for v in range(3, 7):
        for u in range(3, 7):
            for a, b in SHIFTS:
                assert shift_change(img, u, v, -a, -b, 1) == shift_change(img, u - a, v - b, a, b, 1)

History

Hans Moravec built the interest operator for the Stanford Cart, a small robot that found its way among obstacles by stereo vision. His 1980 Stanford thesis describes it in Chapter 5: the score of a window is the minimum of the four sums of squared differences of adjacent pixels, and a window is a feature when its score is the largest among the 25 windows that overlap or touch it. The cart then matched these features between stereo images with a correlator. In 1988 Chris Harris and Mike Stephens analyzed the operator, listed its three faults (the discrete set of shifts, the binary window and the use of the minimum), and fixed them with the gradient form that became the Harris detector.

References

  1. Hans P. Moravec, Obstacle avoidance and navigation in the real world by a seeing robot rover, PhD thesis, Stanford University, 1980 (also Stanford AIM-340 and CMU-RI-TR-80-03), Chapter 5, Interest Operator (four directions, the minimum of the four sums, the local maximum over the 25 windows that overlap or touch a window)
  2. Chris Harris and Mike Stephens, A combined corner and edge detector, Proceedings of the Alvey Vision Conference 1988, Manchester, the section Moravec revisited (the shifts (1,0), (1,1), (0,1), (-1,1) and the three faults of the operator)
  3. Richard Szeliski, Computer Vision, Algorithms and Applications, second edition, Springer, 2022, Chapter 7, Section 7.1.1, Feature detectors (the auto-correlation function of a patch)
  4. Tinne Tuytelaars and Krystian Mikolajczyk, Local invariant feature detectors, a survey, Foundations and Trends in Computer Graphics and Vision 3(3), 177-280, 2008, the part on corner detectors (the Harris detector and its origin in the Moravec operator)

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