Algorithm Search⌘K

Algorithmadvanced

Determinant of Hessian detector

Also called Hessian blob detector, DoH detector.

Find blobs as scale-space maxima of the scale-normalized determinant of the Hessian of the smoothed image.

Time
O(K W H r) worst · average · best
Space
Θ(K W H) extra
Where
H = the image height in pixels; K = the number of scales; W = the image width in pixels; r = the radius of the largest Gaussian kernel
Properties
approximately scale invariantdeterministicnot exactheuristicrotation invariant response
Origin
Tony Lindeberg, 1998

The determinant of Hessian detector, or DoH detector, solves feature detection for blobs. It smooths the image with Gaussians of variance tt over a range of scales, computes at each point and scale the Hessian matrix of second derivatives, and takes the scale-normalized determinant t2(LxxLyy−Lxy2)t^2 (L_{xx} L_{yy} - L_{xy}^2) as the response. The points are the positive maxima of the response in space and scale, and the scale of the maximum gives the size of the blob. The determinant is large only where the image curves strongly in two directions, so it does not respond to straight edges and needs no edge test, unlike the DoG detector. It is the second of the two blob measures in Lindeberg's theory of automatic scale selection, next to the Laplacian of Gaussian. SURF computes an approximation of it with box filters. The cost is O(KWHr)O(KWHr) for KK scales and kernels of radius at most rr.

In plain words

Blur the image by several amounts. At each point and each blur, measure how the brightness bends: how much it curves left to right, top to bottom, and diagonally. Combine these three numbers into one, the determinant, which is large only when the brightness bends the same way in every direction, as on the top of a hill or the bottom of a bowl. A bright spot is a hill and a dark spot is a bowl, so both give a large value. An edge bends in one direction only and gives zero. Multiply by the square of the blur, so that small and large spots can be compared fairly. A spot is found where this value is larger than at all neighbours, in the image and across the blurs. The blur at that point gives the size of the spot.

The problem

The input is a gray digital image II with WW columns and HH rows of real values. A pixel has coordinates (u,v)(u, v): uu is the column and goes right, vv is the row and goes down, and xx and yy name the derivatives along uu and vv. The scale space is L(⋅,t)=gt∗IL(\cdot, t) = g_t \ast I, where gtg_t is the Gaussian of variance t=σ2t = \sigma^2; this page uses a sampled Gaussian cut at 3σ3\sigma and the clamp border rule. The parameters are an increasing list of scales t1<⋯<tKt_1 < \dots < t_K, best with a constant ratio, and a threshold τ≥0\tau \ge 0.

The Hessian of LL is HL=(LxxLxyLxyLyy)\mathcal H L = \begin{pmatrix} L_{xx} & L_{xy} \\ L_{xy} & L_{yy} \end{pmatrix}, and the scale-normalized determinant is

D(u,v,t)=t2det⁡HL=t2(LxxLyy−Lxy2).D(u, v, t) = t^2 \det \mathcal H L = t^2 \big(L_{xx} L_{yy} - L_{xy}^2\big).

The factor t2t^2 is tγt^{\gamma} for each of the two derivatives, with γ=1\gamma = 1: each derivative of order 2 is multiplied by tt. With this factor, a pattern and the same pattern magnified by ss give the same maximum value, at scales that differ by s2s^2. The output is the list of samples where D>τD > \tau and DD is larger than at all 26 neighbours in space and scale, refined to sub-sample position and scale.

The algorithm

  1. DOH(I, t_1, …, t_K, τ) ▷ I is W × H, t_1 < … < t_K
  2. 1for i ← 1 to K do L_i ← g_(t_i) ∗ I ▷ separable Gaussian, clamp border
  3. 2D_i(u, v) ← t_i² (L_xx L_yy - L_xy²) at each pixel, with central second differences
  4. 3blobs ← ∅
  5. 4for each sample (u, v, i) with 2 ≤ i ≤ K - 1, off the border, D_i(u, v) > τ and larger than all 26 neighbours do
  6. 5refine u, v and log t by a parabola through the sample and its two neighbours in each direction
  7. 6add (x̂, ŷ, t̂) to blobs
  8. 7return blobs

Line L2 uses Lxx≈L(u+1,v)−2L(u,v)+L(u−1,v)L_{xx} \approx L(u + 1, v) - 2L(u, v) + L(u - 1, v), the same in vv for LyyL_{yy}, and Lxy≈14(L(u+1,v+1)−L(u−1,v+1)−L(u+1,v−1)+L(u−1,v−1))L_{xy} \approx \frac14 \big(L(u + 1, v + 1) - L(u - 1, v + 1) - L(u + 1, v - 1) + L(u - 1, v - 1)\big). Line L4 keeps only positive maxima. A positive determinant means that both curvatures have the same sign: a bright blob, with both negative, and a dark blob, with both positive, are both maxima of DD. A negative determinant is a saddle. Line L5 fits a parabola in each of the three directions separately; in scale it uses log⁡t\log t, since the scales are spaced by a constant ratio.

Example

Take a 32×3232 \times 32 image of a Gaussian blob I=exp⁡(−((u−16)2+(v−16)2)/(2t0))I = \exp(-((u - 16)^2 + (v - 16)^2) / (2 t_0)) with t0=4t_0 = 4, and the scales ti=2i/2t_i = 2^{i/2} for i=0,…,8i = 0, \dots, 8, from 11 to 1616. The smoothed blob is a Gaussian of variance t0+tt_0 + t, and in the continuous case the center value of DD is

D(16,16,t)=t02 t2(t0+t)4,D(16, 16, t) = \frac{t_0^2\, t^2}{(t_0 + t)^4},

which is largest at t=t0t = t_0, with the value 1/16=0.06251/16 = 0.0625. The discrete values at the center are:

tt 1 1.41 2 2.83 4 5.66 8 11.3 16
computed DD 0.0232 0.0340 0.0455 0.0548 0.0590 0.0560 0.0475 0.0361 0.0251
continuous DD 0.0256 0.0372 0.0494 0.0589 0.0625 0.0589 0.0494 0.0372 0.0256

The largest computed value is at t=4t = 4, and the parabola in log⁡t\log t gives t^=4.12\hat t = 4.12. The detector returns one blob, at (16,16)(16, 16) with t^=4.12\hat t = 4.12. The computed values are about 5 percent low because the second differences of a sampled Gaussian are smaller than the derivatives. For t0=2t_0 = 2 and t0=8t_0 = 8 the selected scales are 2.122.12 and 8.138.13. A dark blob on a white background gives the same point with the same value, and a straight edge gives D=0D = 0 everywhere, since Lyy=Lxy=0L_{yy} = L_{xy} = 0 across a vertical edge.

Correctness

The proof in proofs/correctness.md shows that line L4 returns exactly the strict positive maxima among the 26 neighbours, that the parabola step returns the exact vertex of a parabola, and that for a Gaussian blob of variance t0t_0 the continuous response at the center has its single maximum over tt at t=t0t = t_0, so the selected scale equals the size of the blob. It also shows the reason for the normalization: under a magnification of the image by ss, DD at the corresponding point and the scale s2ts^2 t is the same, so maxima over scale move with the size of the pattern.

That the maxima are useful points on real images is measured, not proved. In the comparison of Mikolajczyk and others, the Hessian based detectors are among the most repeatable; see detector repeatability.

Proof: Correctness of the determinant of Hessian detectorfull

We prove that line L4 returns the strict positive maxima, that the parabola step is exact on parabolas, that the normalized response is unchanged by a magnification, and that for a Gaussian blob the response selects the scale t=t0t = t_0.

Lemma 1 (the maxima). Line L4 returns exactly the samples (u,v,i)(u, v, i) with 2≤i≤K−12 \le i \le K - 1, uu and vv at least one pixel from the border, Di(u,v)>τD_i(u, v) > \tau, and Di(u,v)>Di′(u′,v′)D_i(u, v) > D_{i'}(u', v') for each of the 26 neighbours.

Proof. The loops run over exactly these ranges of ii, uu and vv, so every neighbour is a valid sample. A sample with Di(u,v)≤τD_i(u, v) \le \tau is skipped. For the others, the test "every neighbour is strictly smaller" is evaluated over the 26 offsets (a,b,c)≠(0,0,0)(a, b, c) \ne (0, 0, 0) in {−1,0,1}3\{-1, 0, 1\}^3, and the sample is added exactly when it holds. □\square

Lemma 2 (the parabola step). If f(x)=a−b(x−x0)2f(x) = a - b(x - x_0)^2 with b>0b > 0, then the offset computed from f(−1)f(-1), f(0)f(0), f(1)f(1) is x0x_0.

Proof. f(−1)−2f(0)+f(1)=−2b<0f(-1) - 2f(0) + f(1) = -2b < 0, so the step does not return 00 for a flat case, and f(−1)−f(1)=−b((1+x0)2−(1−x0)2)=−4bx0f(-1) - f(1) = -b\big((1 + x_0)^2 - (1 - x_0)^2\big) = -4b x_0. The step returns 12⋅−4bx0−2b=x0\frac12 \cdot \frac{-4b x_0}{-2b} = x_0. □\square

At a sample of Lemma 1 the center value is larger than both neighbours in each direction, so the denominator f(−1)−2f(0)+f(1)f(-1) - 2f(0) + f(1) is negative and the offset is in (−12,12)(-\frac12, \frac12); the fitted point stays within half a step of the sample.

Lemma 3 (magnification). Let I′(x)=I(x/s)I'(\mathbf x) = I(\mathbf x / s) for s>0s > 0, in the continuous setting. Then D′(sx,s2t)=D(x,t)D'(s\mathbf x, s^2 t) = D(\mathbf x, t).

Proof. A change of variables in the convolution gives L′(sx,s2t)=L(x,t)L'(s\mathbf x, s^2 t) = L(\mathbf x, t), because gs2t(sy)=s−2gt(y)g_{s^2 t}(s\mathbf y) = s^{-2} g_t(\mathbf y) and the area element scales by s2s^2. Each second derivative in x′\mathbf x' is s−2s^{-2} times the one in x\mathbf x, so det⁡HL′(sx,s2t)=s−4det⁡HL(x,t)\det \mathcal H L'(s\mathbf x, s^2 t) = s^{-4} \det \mathcal H L(\mathbf x, t). The factor (s2t)2=s4t2(s^2 t)^2 = s^4 t^2 cancels the s−4s^{-4}. □\square

So a maximum of DD at (x,t)(\mathbf x, t) becomes a maximum of D′D' at (sx,s2t)(s\mathbf x, s^2 t), with the same value: the selected scale follows the size of the pattern.

Proposition 4 (the scale of a Gaussian blob). Let I(x)=exp⁡(−∣x∣2/(2t0))I(\mathbf x) = \exp(-|\mathbf x|^2 / (2 t_0)) in the continuous plane. Then D(0,t)=t02t2/(t0+t)4D(\mathbf 0, t) = t_0^2 t^2 / (t_0 + t)^4, and as a function of t>0t > 0 it has a single maximum, at t=t0t = t_0, with the value 1/161/16.

Proof. I=2πt0 gt0I = 2\pi t_0\, g_{t_0}, and Gaussians add their variances, so L(⋅,t)=2πt0 gt0+tL(\cdot, t) = 2\pi t_0\, g_{t_0 + t}. For gT(x)=12πTe−∣x∣2/(2T)g_T(\mathbf x) = \frac{1}{2\pi T} e^{-|\mathbf x|^2/(2T)}, at x=0\mathbf x = \mathbf 0 we have ∂xxgT=∂yygT=−12πT2\partial_{xx} g_T = \partial_{yy} g_T = -\frac{1}{2\pi T^2} and ∂xygT=0\partial_{xy} g_T = 0. So det⁡HL(0,t)=(2πt0)2⋅14π2(t0+t)4=t02(t0+t)4\det \mathcal H L(\mathbf 0, t) = (2\pi t_0)^2 \cdot \frac{1}{4\pi^2 (t_0 + t)^4} = \frac{t_0^2}{(t_0 + t)^4}, and D=t02t2/(t0+t)4D = t_0^2 t^2 / (t_0 + t)^4. Let ψ(t)=log⁡D=2log⁡t−4log⁡(t0+t)+const\psi(t) = \log D = 2\log t - 4\log(t_0 + t) + \text{const}. Then ψ′(t)=2/t−4/(t0+t)\psi'(t) = 2/t - 4/(t_0 + t), which is positive for t<t0t < t_0, zero at t=t0t = t_0 and negative for t>t0t > t_0. So t0t_0 is the single maximum, and D(0,t0)=t04/(2t0)4=1/16D(\mathbf 0, t_0) = t_0^4 / (2t_0)^4 = 1/16. □\square

Theorem. DOH returns, for each strict positive maximum of Lemma 1, the point refined by the three parabola steps, with the scale exp⁡(log⁡ti+δ⋅12(log⁡ti+1−log⁡ti−1))\exp(\log t_i + \delta \cdot \frac12(\log t_{i+1} - \log t_{i-1})) for the offset δ\delta in scale; and no other point.

Proof. Lines L1 and L2 fill the stack D1,…,DKD_1, \dots, D_K. By Lemma 1, line L4 visits exactly the strict positive maxima. Line L5 computes three offsets as in Lemma 2 and maps the offset in scale to log⁡t\log t with the half spacing of the two neighbouring scales, which is the spacing when the ratio is constant. Line L6 adds one point per maximum, and nothing else adds points. ■\blacksquare

Complexity

The model is the real RAM. Let rr be the radius of the largest kernel, 3tK3\sqrt{t_K}.

  • Line L1 is a separable blur, O(WHr)O(WHr) per scale.
  • Line L2 costs O(WH)O(WH) per scale.
  • Line L4 makes at most 26 comparisons per sample, O(KWH)O(KWH).
  • Line L5 is O(1)O(1) per blob.

The total time is O(KWHr)O(KWHr), and the stack takes Θ(KWH)\Theta(KWH) space. Two things lower the cost in practice. A pyramid halves the image when tt grows by 4, so the larger kernels run on smaller images. SURF replaces the Gaussian second derivatives by box filters, which an integral image evaluates in O(1)O(1) per pixel for any size, so the cost is O(KWH)O(KWH).

Properties

  • No edge response. On a straight edge one curvature is zero and so is DD. The DoG and the Laplacian respond to edges and need a separate edge test.
  • Both polarities. Bright and dark blobs both give positive maxima. The sign of the Laplacian Lxx+LyyL_{xx} + L_{yy} at the point tells them apart.
  • Scale. The normalization makes the selected scale proportional to the size of the pattern. For a Gaussian blob it is exactly t0t_0.
  • Rotation. The determinant of the Hessian does not change under a rotation of the coordinates. On the pixel grid it changes slightly; for rotations by 90°90° it is exact.
  • Brightness. An offset does not change DD. A gain gg multiplies DD by g2g^2.
  • Corners. DD is also positive near the corners of objects, where the smoothed image bends in two directions. On a square of side 12, the scales up to 16 give maxima near the four corners and none at the center, whose scale is larger.

Variants and improvements

  • Fast Hessian. SURF approximates LxxL_{xx}, LyyL_{yy} and LxyL_{xy} by box filters on an integral image, and uses DxxDyy−(0.9Dxy)2D_{xx} D_{yy} - (0.9 D_{xy})^2, where the factor corrects for the box approximation.
  • Hessian-Laplace. Choose the position by the determinant of the Hessian and the scale by the Laplacian, as in the Harris-Laplace detector with the Hessian in place of the Harris measure.
  • Hessian-affine. Adapt an elliptical shape to each Hessian point by the second moment matrix, as in the Harris-affine detector.
  • Laplacian. Use t(Lxx+Lyy)t(L_{xx} + L_{yy}), the trace instead of the determinant, which is the Laplacian of Gaussian blob detector, or its DoG approximation.
  • Better localization. Fit a full quadratic in (u,v,log⁡t)(u, v, \log t), as the DoG detector does, instead of three separate parabolas.

When to use it

Use it to find blobs at all scales when straight edges must not give points, for example on images of man-made scenes. With box filters it is the detector of SURF and is among the fastest scale invariant detectors. For matching under large changes of viewpoint, add affine adaptation (Hessian-affine) or use MSER.

Pitfalls

  • Missing normalization. Without the factor t2t^2, DD decreases with tt for every pattern, and the largest value is always at the smallest scale.
  • Taking minima. Negative values of DD are saddles, not blobs. Search for positive maxima only.
  • Too few scales. A maximum needs a scale below and above. The smallest and largest scales cannot hold a blob, so the range must extend past the sizes of interest.
  • Unequal steps in scale. The parabola in log⁡t\log t assumes a constant ratio between scales. With unequal steps, fit with the actual spacing.
  • Sampling. For small tt, the sampled Gaussian and the differences are poor, and the selected scale is biased. Start at t≥1t \ge 1 or upsample the image.

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.

determinant_of_hessian_detector.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/determinant-of-hessian-detector/. The authors are listed in prov/698GJR.jsonl.

"""Determinant of Hessian (DoH) blob detector with scale selection.

An image is a list of H rows of W floats; pixel (u, v) is img[v][u], with u
the column (to the right) and v the row (down). The scale parameter is the
variance t = sigma^2. L(., t) is the image blurred with a sampled Gaussian of
variance t (cut at radius ceil(3 sigma), normalized, clamp border).

The response is the scale-normalized determinant of the Hessian,

    D(u, v, t) = t^2 (Lxx Lyy - Lxy^2),

with central second differences. A point is a sample (u, v, i), 1 <= i <= K - 2
for K scales, off the border, where D > tau and D is larger than all 26
neighbours in space and scale. It is refined by a parabola in each of u, v
and log t.
"""

import math
from typing import List, Sequence, Tuple

Image = List[List[float]]


def gaussian_kernel(sigma: float) -> List[float]:
    """Sampled Gaussian on -R..R with R = ceil(3 sigma), normalized to sum 1."""
    if sigma <= 0:
        return [1.0]
    rad = max(1, int(math.ceil(3 * sigma)))
    k = [math.exp(-(i * i) / (2 * sigma * sigma)) for i in range(-rad, rad + 1)]
    s = sum(k)
    return [x / s for x in k]


def blur(img: Sequence[Sequence[float]], t: float) -> Image:
    """Separable Gaussian blur of variance t with the clamp border rule."""
    h, w = len(img), len(img[0])
    k = gaussian_kernel(math.sqrt(t))
    r = len(k) // 2
    tmp = [[sum(k[j] * row[min(max(u + j - r, 0), w - 1)] for j in range(len(k))) for u in range(w)]
           for row in img]
    return [[sum(k[j] * tmp[min(max(v + j - r, 0), h - 1)][u] for j in range(len(k))) for u in range(w)]
            for v in range(h)]


def doh_response(img: Sequence[Sequence[float]], t: float) -> Image:
    """t^2 (Lxx Lyy - Lxy^2) at each pixel; 0 on the one-pixel border."""
    L = blur(img, t)
    h, w = len(L), len(L[0])
    out = [[0.0] * w for _ in range(h)]
    for v in range(1, h - 1):
        for u in range(1, w - 1):
            c = L[v][u]
            lxx = L[v][u + 1] + L[v][u - 1] - 2 * c
            lyy = L[v + 1][u] + L[v - 1][u] - 2 * c
            lxy = (L[v + 1][u + 1] - L[v + 1][u - 1] - L[v - 1][u + 1] + L[v - 1][u - 1]) / 4
            out[v][u] = t * t * (lxx * lyy - lxy * lxy)
    return out


def scale_maxima(stack: List[Image], tau: float) -> List[Tuple[int, int, int]]:
    """Samples (i, u, v) off the border of space and scale with value > tau and > all 26 neighbours."""
    out = []
    k, h, w = len(stack), len(stack[0]), len(stack[0][0])
    for i in range(1, k - 1):
        for v in range(1, h - 1):
            for u in range(1, w - 1):
                x = stack[i][v][u]
                if x <= tau:
                    continue
                if all(stack[i + a][v + b][u + c] < x
                       for a in (-1, 0, 1) for b in (-1, 0, 1) for c in (-1, 0, 1) if a or b or c):
                    out.append((i, u, v))
    return out


def parabola_offset(fm: float, f0: float, fp: float) -> float:
    """Offset of the vertex of the parabola through (-1, fm), (0, f0), (1, fp); 0 if flat."""
    den = fm - 2 * f0 + fp
    if den >= 0:
        return 0.0
    return 0.5 * (fm - fp) / den


def doh_blobs(img: Sequence[Sequence[float]], scales: Sequence[float], tau: float = 0.0):
    """Return blobs (x, y, t, D) for the scale list t_0 < t_1 < ... (best with a constant ratio).

    Precondition: img is a rectangular list of rows of floats, at least 3 x 3,
    and scales has at least 3 increasing positive values.
    """
    stack = [doh_response(img, t) for t in scales]  # @line L1 @line L2
    blobs = []  # @line L3
    for i, u, v in scale_maxima(stack, tau):  # @line L4
        S = stack[i]
        du = parabola_offset(S[v][u - 1], S[v][u], S[v][u + 1])  # @line L5
        dv = parabola_offset(S[v - 1][u], S[v][u], S[v + 1][u])
        di = parabola_offset(stack[i - 1][v][u], S[v][u], stack[i + 1][v][u])
        lo, hi = math.log(scales[i - 1]), math.log(scales[i + 1])
        lt = math.log(scales[i]) + di * ((hi - lo) / 2)
        blobs.append((u + du, v + dv, math.exp(lt), S[v][u]))  # @line L6
    return blobs  # @line L7
test_determinant_of_hessian_detector.py 124 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/determinant-of-hessian-detector/. The authors are listed in prov/698GJR.jsonl.

import math
import random

from determinant_of_hessian_detector import (
    doh_blobs,
    doh_response,
    gaussian_kernel,
    parabola_offset,
    scale_maxima,
)

SCALES = [2 ** (i / 2) for i in range(9)]  # 1, 1.41, 2, ..., 16


def blob(n, cx, cy, t0, amp=1.0):
    return [[amp * math.exp(-((u - cx) ** 2 + (v - cy) ** 2) / (2 * t0)) for u in range(n)] for v in range(n)]


def direct_response(img, t):
    """2D convolution, then the Hessian by the same differences; independent of the separable code."""
    k = gaussian_kernel(math.sqrt(t))
    r = len(k) // 2
    h, w = len(img), len(img[0])
    L = [[sum(k[i + r] * k[j + r] * img[min(max(v + j, 0), h - 1)][min(max(u + i, 0), w - 1)]
              for i in range(-r, r + 1) for j in range(-r, r + 1)) for u in range(w)] for v in range(h)]
    out = [[0.0] * w for _ in range(h)]
    for v in range(1, h - 1):
        for u in range(1, w - 1):
            # A 3 x 3 Taylor fit gives the same second differences.
            m = [[L[v + b][u + a] for a in (-1, 0, 1)] for b in (-1, 0, 1)]
            lxx = m[1][2] - 2 * m[1][1] + m[1][0]
            lyy = m[2][1] - 2 * m[1][1] + m[0][1]
            lxy = (m[2][2] - m[2][0] - m[0][2] + m[0][0]) / 4
            out[v][u] = t * t * (lxx * lyy - lxy ** 2)
    return out


def oracle_maxima(stack, tau):
    out = []
    for i in range(1, len(stack) - 1):
        for v in range(1, len(stack[0]) - 1):
            for u in range(1, len(stack[0][0]) - 1):
                x = stack[i][v][u]
                nb = [stack[i + a][v + b][u + c] for a in (-1, 0, 1) for b in (-1, 0, 1) for c in (-1, 0, 1)]
                nb.remove(x)
                if x > tau and max(nb) < x:
                    out.append((i, u, v))
    return out


def test_response_matches_direct_convolution():
    rng = random.Random(8)
    for _ in range(10):
        w, h = rng.randint(3, 7), rng.randint(3, 7)
        img = [[rng.random() for _ in range(w)] for _ in range(h)]
        for t in (0.5, 1.5):
            a, b = doh_response(img, t), direct_response(img, t)
            assert all(abs(x - y) < 1e-12 for ra, rb in zip(a, b) for x, y in zip(ra, rb))


def test_scale_maxima_against_oracle():
    rng = random.Random(1998)
    for _ in range(600):
        k, h, w = rng.randint(3, 5), rng.randint(3, 6), rng.randint(3, 6)
        stack = [[[rng.randint(-3, 3) for _ in range(w)] for _ in range(h)] for _ in range(k)]
        tau = rng.choice([-10, 0, 1])
        assert sorted(scale_maxima(stack, tau)) == sorted(oracle_maxima(stack, tau))


def test_parabola_offset():
    for x0 in (-0.5, -0.2, 0.0, 0.3, 0.5):
        f = lambda x: 3 - 2 * (x - x0) ** 2
        assert abs(parabola_offset(f(-1), f(0), f(1)) - x0) < 1e-12
    assert parabola_offset(1.0, 1.0, 1.0) == 0.0


def test_worked_example_blob():
    img = blob(32, 16, 16, 4.0)
    (x, y, t, d), = doh_blobs(img, SCALES, 1e-5)
    assert (x, y) == (16.0, 16.0)
    assert abs(t - 4.12) < 0.01 and abs(d - 0.05898) < 1e-5
    # Continuous value at the centre: t0^2 t^2 / (t0 + t)^4, which is 1/16 at t = t0.
    centre = [doh_response(img, s)[16][16] for s in SCALES]
    for s, c in zip(SCALES, centre):
        want = 16 * s * s / (4 + s) ** 4
        assert abs(c - want) < 0.1 * want
    assert max(range(9), key=lambda i: centre[i]) == 4  # t = 4


def test_selected_scale_follows_blob_variance():
    for t0 in (2.0, 4.0, 8.0):
        (x, y, t, d), = doh_blobs(blob(32, 16, 16, t0), SCALES, 1e-5)
        assert abs(t - t0) < 0.08 * t0
        assert abs(x - 16) < 1e-9 and abs(y - 16) < 1e-9


def test_dark_blob_and_offset_give_the_same_blob():
    img = blob(32, 16, 16, 4.0)
    a = doh_blobs(img, SCALES, 1e-5)
    b = doh_blobs([[1 - p for p in r] for r in img], SCALES, 1e-5)
    c = doh_blobs([[p + 5 for p in r] for r in img], SCALES, 1e-5)
    for other in (b, c):
        assert len(other) == 1 and all(abs(p - q) < 1e-9 for p, q in zip(a[0], other[0]))


def test_straight_edge_and_flat_give_nothing():
    edge = [[1.0 if u >= 16 else 0.0 for u in range(32)] for v in range(32)]
    assert all(abs(x) < 1e-12 for row in doh_response(edge, 2.0) for x in row)
    assert doh_blobs(edge, SCALES, 1e-5) == []
    assert doh_blobs([[0.3] * 10 for _ in range(10)], [1, 2, 4], 0.0) == []


def test_rotation_by_90_degrees():
    rng = random.Random(31)
    h, w = 7, 9
    img = [[rng.random() for _ in range(w)] for _ in range(h)]
    rot = [[img[h - 1 - j][i] for j in range(h)] for i in range(w)]
    a, b = doh_response(img, 1.0), doh_response(rot, 1.0)
    for v in range(h):
        for u in range(w):
            assert abs(a[v][u] - b[u][h - 1 - v]) < 1e-12

History

Paul Beaudet proposed the determinant of the Hessian as a rotation invariant interest operator in 1978, at a single scale. Tony Lindeberg built the theory of scale selection in the 1990s and showed in his 1998 paper that the scale-normalized determinant and the scale-normalized Laplacian, with γ=1\gamma = 1, select the scale of a blob, and he used both as blob detectors. Mikolajczyk and Schmid used the Hessian in the Hessian-Laplace and Hessian-affine detectors, and Bay and others made it fast with box filters in SURF in 2006, with the journal version in 2008.

References

  1. Tony Lindeberg, Feature detection with automatic scale selection, International Journal of Computer Vision 30(2), 79-116, 1998, the sections on blob detection (the scale-normalized Laplacian and the scale-normalized determinant of the Hessian, and the scale selected for a Gaussian blob)
  2. Herbert Bay, Andreas Ess, Tinne Tuytelaars and Luc Van Gool, Speeded-up robust features (SURF), Computer Vision and Image Understanding 110(3), 346-359, 2008, the section on the fast Hessian detector (box filters on an integral image)
  3. Krystian Mikolajczyk, Tinne Tuytelaars, Cordelia Schmid, Andrew Zisserman, Jiri Matas, Frederik Schaffalitzky, Timor Kadir and Luc Van Gool, A comparison of affine region detectors, International Journal of Computer Vision 65(1-2), 43-72, 2005, the section on the Hessian-affine detector
  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 blob detectors (the Hessian detector)

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