Algorithmcore
Difference-of-Gaussians detector
Also called DoG detector, DoG keypoint detector.
Find blobs as extrema in space and scale of the difference of adjacent Gaussian smoothed images, a cheap approximation of the scale-normalized Laplacian.
- Solves
- Feature detection
- Time
- O(s W H) worst · average · best
- Space
- Θ(s W H) extra
- Where
- H = the image height in pixels; W = the image width in pixels; s = the number of scales per octave
- Model
- Real RAM
- Properties
- approximately scale invariantdeterministicnot exactheuristicrotation invariant response
- Evidence
- Proof sketchCode in 1 languages
- Origin
- David G. Lowe, 2004
The Difference-of-Gaussians detector, or DoG detector, solves feature detection for blobs at all scales. It blurs the image with Gaussians of growing width , subtracts each blurred image from the next, and keeps the points that are larger or smaller than all 26 neighbours in space and in scale. Each kept point is refined to sub-pixel position and sub-level scale by a quadratic fit, and points with low contrast or on edges are dropped. The difference of two Gaussians of widths and is close to times the scale-normalized Laplacian of Gaussian, so the detector is a fast form of Lindeberg's automatic scale selection with the Laplacian. This page is the detector only. The SIFT page covers the whole pipeline, which adds an orientation and a descriptor to each DoG keypoint and matches them. The cost is for scales per octave.
In plain words
Blur the image a little, then a little more, and so on. Subtract each blurred copy from the next one. What is left is strong where the image has a spot about the size of the blur: a bright spot gives a deep valley, a dark spot a high peak. A spot of a given size gives its strongest answer at the blur that matches its size. So look for the points that are stronger than everything around them, both in the image and in the list of blurs. Each such point gives a position and a size. Then throw away the weak ones and the ones that lie along an edge, because their position along the edge is not well defined. To save time, halve the image each time the blur doubles.
The problem
The input is a gray digital image with columns and rows and values in . A pixel has coordinates : is the column and goes right, is the row and goes down, and its center is at the integer point . The blur uses the clamp border rule. The parameters are the number of scales per octave, the base scale , the number of octaves , the contrast threshold , and the edge ratio . Lowe uses , , and , and he assumes that the input already has a blur of .
The Gaussian scale space is , and the difference of Gaussians is
Since the Gaussian solves the heat equation , the difference quotient gives
so is the scale-normalized Laplacian times the constant . The constant is the same at all scales and does not move the extrema. The output is a list of keypoints in the pixel units of the input, each with the value of at the point.
The algorithm
DOG-DETECTOR(I, s, σ0, O, c, r) ▷ I is W × H with values in [0, 1]- 1
base ← I blurred from the assumed 0.5 to σ0 - 2
for o ← 0 to O - 1 do - 3
G_i ← base blurred to σ0 k^i for i = 0, …, s + 2 ▷ k = 2^(1/s), in the pixels of octave o - 4
D_i ← G_(i+1) - G_i for i = 0, …, s + 1 - 5
for each sample (u, v, i) with 1 ≤ i ≤ s, off the border, larger than all 26 neighbours or smaller than all of them do - 6
fit a quadratic to D at the sample; while an offset is above 0.5, move to the neighbour sample and fit again (at most 5 times) - 7
if |D(fitted point)| ≥ c and tr(H)² · r < (r + 1)² · det(H) with det(H) > 0 then - 8
add (2^o x̂, 2^o ŷ, σ0 2^(o + î/s)) to keypoints - 9
base ← G_s sampled at every second pixel - 10
return keypoints
Lines L3 and L4 build one octave: Gaussian images and DoG images. Line L5 looks for extrema only in the middle DoG images, because each needs a level above and below, and these levels cover one doubling of . A sample is compared with its 8 neighbours in its own level and the 9 neighbours in each of the two levels next to it.
Line L6 is the fit of Brown and Lowe. With the gradient and the Hessian of in , taken by central differences, the second order Taylor expansion has its vertex at , with the value . If any component of is above , the vertex is nearer to another sample, and the fit moves there. Line L7 drops points with low contrast and points on edges. The edge test uses the spatial Hessian : its eigenvalues are the curvatures of across and along the point, and the ratio grows with the ratio of the eigenvalues. The test keeps the point when the ratio of the curvatures is below , without an eigenvalue computation. Line L9 starts the next octave. Image of the octave has blur , so every second pixel of it has blur in the new pixel units.
The implementation blurs each directly from the base by . Lowe blurs each image from the previous one; the two agree because blurs add in squares, up to the cut of the kernels.
Example
Take a image of a bright Gaussian blob of width and height , centered at , on a black background. Use , and two octaves. The levels of the first octave have . At the center the five DoG values are
The smallest is at , and it is smaller than all 26 neighbours, so is a candidate. The fit stays at by symmetry and moves the level to , so , with . The contrast is above and the blob is round, so the point passes. It is the only keypoint. An inverted image, a dark blob on white, gives the same point with .
The scale is not , and the reason is exact. The blurred blob has variance with , since the detector assumes the input blur . At the center, is proportional to with , and the derivative in is zero at . So the DoG between and peaks when the geometric mean of the two widths matches the blob: , close to the fitted .
Three other inputs show the limits. A straight vertical edge gives candidates along the edge, and all fail the edge test. The same blob with height gives and no keypoint. A blob with peaks at , below the first searched level , and is not found; this is why Lowe doubles the input image before the first octave.
Correctness
The detector finds what it defines: the samples of that are strict extrema among their 26 neighbours, refined by the fit and filtered by the two tests. The proof in proofs/correctness.md shows that line L5 finds exactly those samples, that the fit of line L6 returns the exact vertex when is a quadratic near the point, and that the edge test keeps exactly the points with and a ratio of curvatures below .
Why the extrema are the right points is a result of scale-space theory. Lindeberg showed that the extrema over scale of the scale-normalized Laplacian select a scale proportional to the size of a blob, and the derivation above shows that is that operator up to a constant. For a Gaussian blob the selection is exact, as the example computes. That the points are repeatable on real images is measured, not proved; see detector repeatability.
Proof: Correctness of the Difference-of-Gaussians detectorfull
We prove four facts: the extremum search of line L5 returns exactly the strict extrema among the 26 neighbours; the fit of line L6 returns the exact vertex of a quadratic; the edge test keeps exactly the points with a ratio of curvatures below ; and for a Gaussian blob the DoG peaks at .
Lemma 1 (the extremum search). Line L5 returns exactly the samples with , and , for an octave of size , such that for all 26 neighbours with , or for all of them.
Proof. The bounds on , and are the ranges of the loops, and they make every neighbour a valid sample. The implementation keeps two flags, "larger than all" and "smaller than all", both true at the start. A neighbour with a value the sample clears the first, and a neighbour with a value the sample clears the second. So after all 26 neighbours the first flag is true exactly when every neighbour is strictly smaller, and the second exactly when every neighbour is strictly larger. The early exit happens only when both flags are false, and then neither can become true again, so it does not change the result.
Lemma 2 (central differences are exact on quadratics). Let on with symmetric. At each point , the central differences of line L6 give and the Hessian exactly.
Proof. Write for the unit vectors. Then , because the terms of even order cancel; dividing by gives the -th component of the gradient. Also . For , expands to , since all other terms cancel in pairs; dividing by gives .
Lemma 3 (the fit). If equals a quadratic with an invertible on all the samples read by the fit, then each step of line L6 computes the vertex , and when the step does not move, it returns and the value .
Proof. At the sample , Lemma 2 gives and . The offset is , so at every step. The step returns when each component of is at most in absolute value; otherwise it moves to , which is the nearest sample to in each coordinate, and the next step returns, unless is at a distance of exactly from two samples. The value is . Since and , we get .
Lemma 4 (the edge test). Let be a symmetric matrix with eigenvalues and , and let . The test " and " holds exactly when and have the same sign and .
Proof. and . means that and are nonzero with the same sign. Then let , swapping the names if needed. The quotient . The function is strictly increasing for , since for . So , which after multiplication by is the test, holds exactly when .
Proposition 5 (the scale of a Gaussian blob). Let the image be a Gaussian of variance , and let . The value at the center of , as a function of , has its single extremum at .
Proof. Gaussians add their variances under convolution, and a 2D Gaussian of variance has the value at its center. So the central value is , which is negative for and tends to at both ends. Its derivative is . It is zero when , that is , so , and this is the only zero for .
Theorem. DOG-DETECTOR returns, for each octave, the samples of Lemma 1 whose fit converges within the move limit, whose fitted value has absolute value at least , and whose spatial Hessian passes the test of Lemma 4, each mapped to the input pixel units by the factor and to the scale .
Proof. By Lemma 1, line L5 visits exactly the strict extrema. Line L6 discards a candidate when the fit does not converge or leaves the valid range; Lemma 3 shows what the fit returns when is locally quadratic. Line L7 applies the contrast test and, by Lemma 4, the edge test. Line L8 maps the point: pixel of octave is pixel of the input, since line L9 keeps every second pixel starting at , and level of octave has blur in octave pixels, which is in input pixels. Line L9 is a valid start of the next octave because has blur , which is in units of the new pixels.
Complexity
The model is the real RAM. Let .
- With fixed, each blur uses a kernel of constant size, so lines L3 and L4 cost in the first octave.
- Line L5 makes at most 26 comparisons per DoG sample, .
- Lines L6 to L8 cost per candidate, at most 5 solves of a system.
- Each octave has a quarter of the pixels of the one before, so the octaves together cost at most times the first one.
The total time is , and the space is for the images of one octave. Doubling the input before the first octave, as Lowe does, multiplies the cost by about 4.
Properties
- Approximately scale invariant. A change of scale of the image by moves the extrema levels, up to the sampling of space. Other factors fall between levels, where the fit finds them.
- Rotation. The Gaussian and the Laplacian are isotropic, so the response does not change under rotation, up to the sampling grid.
- Brightness. An offset does not change . A gain multiplies and so changes which points pass the contrast threshold.
- Blobs, not corners. The response is large at the center of a spot of the matching size. Corners give a weaker response near the corner, and edges are removed by the edge test.
- Both polarities. Bright blobs give minima and dark blobs give maxima, and both are kept.
- Approximation. The DoG is close to the scale-normalized Laplacian only for near . For the Gaussian blob the peak is at instead of , a fixed factor that is the same for every blob and so does not hurt the invariance.
Variants and improvements
- Laplacian of Gaussian. Compute directly, as in Lindeberg's blob detector. It is more costly and the extrema are almost the same.
- Determinant of the Hessian. Use , which does not respond to edges and needs no edge test. See the DoH detector, and SURF for a fast box-filter form.
- Harris-Laplace. Choose the position by the Harris response and only the scale by the Laplacian. See the Harris-Laplace detector.
- Affine shape. Adapt an ellipse to each point by the second moment matrix, as in the Harris-affine detector.
- Nonlinear scale space. KAZE replaces the Gaussian by a nonlinear diffusion that keeps edges sharp.
When to use it
Use it to find keypoints for matching between images taken at different scales and rotations: panoramas, structure from motion, object recognition. It is the standard choice when the SIFT descriptor follows. For real-time work FAST or a box-filter Hessian is faster. For large viewpoint changes, add affine adaptation or use MSER.
Pitfalls
- Missing small blobs. The first searched level is , so blobs smaller than that are lost. Double the image before the first octave, as Lowe does.
- Wrong input range. The threshold assumes values in and . For 8-bit values, scale it by 255, and for other , by relative to .
- Strict comparison. The test must be strict: on a flat area every sample equals its neighbours, and a test with would return every sample.
- Skipping the move in the fit. If an offset is above and the fit does not move, the refined point can be far from the sample and wrong.
- Wrong blur of the next octave. The next octave starts from image , the one with blur , not from the last 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.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/difference-of-gaussians-detector/. The authors are listed in prov/832KGB.jsonl.
"""Difference-of-Gaussians (DoG) keypoint detector, the detector part of SIFT.
An image is a list of H rows of W floats in [0, 1]; pixel (u, v) is img[v][u],
with u the column (to the right) and v the row (down). The blur is a sampled
Gaussian, cut at radius ceil(3 sigma) and normalized to sum 1, applied to rows
and then to columns with the clamp border rule.
Each octave has s + 3 Gaussian images with sigma_i = sigma0 k^i, k = 2^(1/s),
in the pixel units of the octave, and s + 2 DoG images D_i = G_(i+1) - G_i.
A sample (u, v, i) with 1 <= i <= s, not on the border of the octave, is a
candidate when it is larger than all 26 neighbours or smaller than all of
them. A candidate is refined by fitting a quadratic to D (a 3 x 3 solve). It
is kept when |D| at the fitted point is at least the contrast threshold and
the spatial Hessian passes the edge test tr^2 / det < (r + 1)^2 / r.
"""
import math
from typing import List, Optional, 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]], sigma: float) -> Image:
"""Separable Gaussian blur with the clamp border rule: rows, then columns."""
h, w = len(img), len(img[0])
k = gaussian_kernel(sigma)
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 octave_stack(base: Image, s: int, sigma0: float) -> Tuple[List[Image], List[Image]]:
"""Return the s + 3 Gaussian images and the s + 2 DoG images of one octave.
base has blur sigma0. Image i is base blurred by sqrt(sigma_i^2 - sigma0^2).
"""
k = 2.0 ** (1.0 / s)
gauss = []
for i in range(s + 3):
si = sigma0 * k ** i
gauss.append(blur(base, math.sqrt(max(si * si - sigma0 * sigma0, 0.0))) if i else [row[:] for row in base])
dog = [[[a - b for a, b in zip(r1, r0)] for r1, r0 in zip(gauss[i + 1], gauss[i])] for i in range(s + 2)]
return gauss, dog
def find_extrema(dog: List[Image]) -> List[Tuple[int, int, int]]:
"""Samples (i, u, v), 1 <= i <= len(dog) - 2, off the border, larger or smaller than all 26 neighbours."""
out = []
h, w = len(dog[0]), len(dog[0][0])
for i in range(1, len(dog) - 1):
for v in range(1, h - 1):
for u in range(1, w - 1):
x = dog[i][v][u]
hi = lo = True
for di in (-1, 0, 1):
plane = dog[i + di]
for dv in (-1, 0, 1):
row = plane[v + dv]
for du in (-1, 0, 1):
if di == 0 and dv == 0 and du == 0:
continue
y = row[u + du]
if y >= x:
hi = False
if y <= x:
lo = False
if not (hi or lo):
break
if hi or lo:
out.append((i, u, v))
return out
def _solve3(m: List[List[float]], b: List[float]) -> Optional[List[float]]:
"""Solve m x = b by Cramer's rule; None if m is singular."""
def det(a):
return (a[0][0] * (a[1][1] * a[2][2] - a[1][2] * a[2][1])
- a[0][1] * (a[1][0] * a[2][2] - a[1][2] * a[2][0])
+ a[0][2] * (a[1][0] * a[2][1] - a[1][1] * a[2][0]))
d = det(m)
if abs(d) < 1e-15:
return None
out = []
for c in range(3):
a = [[b[r] if j == c else m[r][j] for j in range(3)] for r in range(3)]
out.append(det(a) / d)
return out
def refine(dog: List[Image], i: int, u: int, v: int, max_steps: int = 5):
"""Fit a quadratic to D around (u, v, i) and move to a neighbour while an offset exceeds 0.5.
Return (u + du, v + dv, i + di, value, (dxx, dyy, dxy)) or None.
"""
h, w = len(dog[0]), len(dog[0][0])
for _ in range(max_steps):
d = lambda a, b, c: dog[c][b][a]
g = [(d(u + 1, v, i) - d(u - 1, v, i)) / 2,
(d(u, v + 1, i) - d(u, v - 1, i)) / 2,
(d(u, v, i + 1) - d(u, v, i - 1)) / 2]
c0 = d(u, v, i)
dxx = d(u + 1, v, i) + d(u - 1, v, i) - 2 * c0
dyy = d(u, v + 1, i) + d(u, v - 1, i) - 2 * c0
dss = d(u, v, i + 1) + d(u, v, i - 1) - 2 * c0
dxy = (d(u + 1, v + 1, i) - d(u - 1, v + 1, i) - d(u + 1, v - 1, i) + d(u - 1, v - 1, i)) / 4
dxs = (d(u + 1, v, i + 1) - d(u - 1, v, i + 1) - d(u + 1, v, i - 1) + d(u - 1, v, i - 1)) / 4
dys = (d(u, v + 1, i + 1) - d(u, v - 1, i + 1) - d(u, v + 1, i - 1) + d(u, v - 1, i - 1)) / 4
hess = [[dxx, dxy, dxs], [dxy, dyy, dys], [dxs, dys, dss]]
off = _solve3(hess, [-x for x in g])
if off is None:
return None
if all(abs(x) <= 0.5 for x in off):
value = c0 + 0.5 * sum(a * b for a, b in zip(g, off))
return (u + off[0], v + off[1], i + off[2], value, (dxx, dyy, dxy))
u += int(round(off[0]))
v += int(round(off[1]))
i += int(round(off[2]))
if not (1 <= i <= len(dog) - 2 and 1 <= u <= w - 2 and 1 <= v <= h - 2):
return None
return None
def passes_edge_test(dxx: float, dyy: float, dxy: float, r: float = 10.0) -> bool:
"""tr^2 / det < (r + 1)^2 / r with det > 0."""
tr, det = dxx + dyy, dxx * dyy - dxy * dxy
return det > 0 and tr * tr * r < (r + 1) ** 2 * det
def dog_keypoints(img: Sequence[Sequence[float]], s: int = 3, sigma0: float = 1.6, octaves: int = 2,
contrast: float = 0.03, edge_r: float = 10.0, sigma_in: float = 0.5):
"""Return keypoints (x, y, sigma, value) in the pixel units of the input image.
Precondition: img is a rectangular list of rows of floats in [0, 1],
s >= 1, 0 <= sigma_in < sigma0 and octaves >= 1. An octave smaller than
3 x 3 pixels is not searched.
"""
base = blur(img, math.sqrt(sigma0 * sigma0 - sigma_in * sigma_in)) # @line L1
keys = []
for o in range(octaves): # @line L2
if len(base) < 3 or len(base[0]) < 3:
break
gauss, dog = octave_stack(base, s, sigma0) # @line L3 @line L4
for i, u, v in find_extrema(dog): # @line L5
fit = refine(dog, i, u, v) # @line L6
if fit is None:
continue
x, y, si, value, (dxx, dyy, dxy) = fit
if abs(value) >= contrast and passes_edge_test(dxx, dyy, dxy, edge_r): # @line L7
f = 2 ** o
keys.append((x * f, y * f, sigma0 * 2 ** (o + si / s), value)) # @line L8
base = [row[::2] for row in gauss[s][::2]] # @line L9
return keys # @line L10
test_difference_of_gaussians_detector.py 151 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/difference-of-gaussians-detector/. The authors are listed in prov/832KGB.jsonl.
import math
import random
from difference_of_gaussians_detector import (
blur,
dog_keypoints,
find_extrema,
gaussian_kernel,
octave_stack,
passes_edge_test,
refine,
)
def blob(n, cx, cy, sb, amp=1.0):
return [[amp * math.exp(-((u - cx) ** 2 + (v - cy) ** 2) / (2 * sb * sb)) for u in range(n)] for v in range(n)]
def direct_blur(img, sigma):
"""2D convolution with the outer product of the kernel, clamp border."""
k = gaussian_kernel(sigma)
r = len(k) // 2
h, w = len(img), len(img[0])
out = []
for v in range(h):
row = []
for u in range(w):
acc = 0.0
for j in range(-r, r + 1):
for i in range(-r, r + 1):
acc += k[i + r] * k[j + r] * img[min(max(v + j, 0), h - 1)][min(max(u + i, 0), w - 1)]
row.append(acc)
out.append(row)
return out
def oracle_extrema(dog):
out = []
levels, h, w = len(dog), len(dog[0]), len(dog[0][0])
for i in range(1, levels - 1):
for v in range(1, h - 1):
for u in range(1, w - 1):
x = dog[i][v][u]
nb = [dog[i + a][v + b][u + c] for a in (-1, 0, 1) for b in (-1, 0, 1) for c in (-1, 0, 1)
if (a, b, c) != (0, 0, 0)]
if all(y < x for y in nb) or all(y > x for y in nb):
out.append((i, u, v))
return out
def test_kernel_is_normalized_and_symmetric():
for sigma in (0.5, 1.0, 1.6, 2.7):
k = gaussian_kernel(sigma)
assert abs(sum(k) - 1) < 1e-12
assert k == k[::-1]
assert len(k) == 2 * math.ceil(3 * sigma) + 1
def test_separable_blur_matches_direct_convolution():
rng = random.Random(4)
for _ in range(15):
w, h = rng.randint(3, 8), rng.randint(3, 8)
img = [[rng.random() for _ in range(w)] for _ in range(h)]
for sigma in (0.7, 1.3):
a, b = blur(img, sigma), direct_blur(img, sigma)
assert all(abs(x - y) < 1e-12 for ra, rb in zip(a, b) for x, y in zip(ra, rb))
def test_extrema_against_oracle():
rng = random.Random(2004)
for _ in range(600):
levels, h, w = rng.randint(3, 5), rng.randint(3, 6), rng.randint(3, 6)
dog = [[[rng.randint(-3, 3) for _ in range(w)] for _ in range(h)] for _ in range(levels)]
assert sorted(find_extrema(dog)) == sorted(oracle_extrema(dog))
def test_refine_recovers_the_vertex_of_a_quadratic():
rng = random.Random(9)
for _ in range(50):
u0, v0, i0 = rng.uniform(3.6, 5.4), rng.uniform(3.6, 5.4), rng.uniform(1.6, 2.4)
c = rng.uniform(0.1, 1)
def q(u, v, i):
du, dv, di = u - u0, v - v0, i - i0
return c - (2 * du * du + 3 * dv * dv + di * di + du * dv + 0.5 * du * di)
dog = [[[q(u, v, i) for u in range(9)] for v in range(9)] for i in range(5)]
# The vertex can be more than 0.5 away from (4, 4, 2), so the fit may have to move.
fit = refine(dog, 2, 4, 4, 5)
assert fit is not None
x, y, s, value, _ = fit
assert abs(x - u0) < 1e-9 and abs(y - v0) < 1e-9 and abs(s - i0) < 1e-9
assert abs(value - c) < 1e-9
fit2 = refine(dog, 1 if i0 > 2 else 3, 3, 6, 5)
assert fit2 is not None and abs(fit2[0] - u0) < 1e-9 and abs(fit2[2] - i0) < 1e-9
def test_edge_test():
assert passes_edge_test(-1.0, -1.0, 0.0)
assert passes_edge_test(-1.0, -9.0, 0.0) # ratio 9 < 10
assert not passes_edge_test(-1.0, -11.0, 0.0) # ratio 11 > 10
assert not passes_edge_test(-1.0, 1.0, 0.0) # saddle
assert not passes_edge_test(-1.0, -1.0, 1.0) # det = 0
def test_worked_example_blob():
img = blob(32, 16, 16, 3.0)
base = blur(img, math.sqrt(1.6 ** 2 - 0.5 ** 2))
_, dog = octave_stack(base, 3, 1.6)
centre = [dog[i][16][16] for i in range(5)]
assert [round(x, 4) for x in centre] == [-0.0933, -0.1096, -0.1186, -0.1141, -0.0993]
keys = dog_keypoints(img)
assert len(keys) == 1
x, y, sigma, value = keys[0]
assert abs(x - 16) < 1e-6 and abs(y - 16) < 1e-6
assert abs(sigma - 2.639) < 1e-3 and abs(value + 0.1188) < 1e-4
# The DoG between sigma and k sigma peaks at sigma^2 = t0 / k, with t0 the blob variance less 0.5^2.
assert abs(sigma - math.sqrt((9 - 0.25) / 2 ** (1 / 3))) < 0.01
def test_blob_scale_follows_blob_size_and_polarity():
for sb in (3.0, 4.0):
(x, y, sigma, value), = dog_keypoints(blob(32, 16, 16, sb))
assert abs(sigma - math.sqrt((sb * sb - 0.25) / 2 ** (1 / 3))) < 0.03 * sigma
assert value < 0
dark = [[1 - p for p in r] for r in blob(32, 16, 16, 3.0)]
(x, y, sigma, value), = dog_keypoints(dark)
assert value > 0 and abs(sigma - 2.639) < 1e-3
def test_small_blob_needs_a_finer_first_level():
# sigma 1.73 is below the first searched level sigma0 k = 2.02.
assert dog_keypoints(blob(32, 16, 16, 2.0)) == []
def test_edge_and_flat_and_low_contrast_give_nothing():
edge = [[1.0 if u >= 16 else 0.0 for u in range(32)] for v in range(32)]
assert dog_keypoints(edge) == []
assert dog_keypoints([[0.5] * 20 for _ in range(20)]) == []
assert dog_keypoints(blob(32, 16, 16, 3.0, 0.2)) == []
def test_offset_does_not_move_keypoints():
img = blob(32, 15, 17, 3.5, 0.6)
a = dog_keypoints(img)
b = dog_keypoints([[p + 0.3 for p in r] for r in img])
assert len(a) == len(b) == 1
assert all(abs(p - q) < 1e-9 for p, q in zip(a[0], b[0]))
History
The difference of Gaussians was used as a model of center-surround receptive fields in the retina, and as a band-pass pyramid in early image analysis. Lindeberg's scale-space theory of the 1990s gave the scale-normalized Laplacian and the rule to select scales at its extrema. Lowe used the DoG as a fast approximation of that operator for the keypoints of SIFT, first at ICCV 1999 and in full in his 2004 journal paper, which also added the quadratic fit, after Brown and Lowe (2002), and the edge test. The DoG detector became the most used scale invariant keypoint detector of the next decade.
References
- David G. Lowe, Distinctive image features from scale-invariant keypoints, International Journal of Computer Vision 60(2), 91-110, 2004, Section 3 (the DoG and its relation to the scale-normalized Laplacian, the 26 neighbours, the choice of 3 scales per octave and sigma = 1.6), Section 4 (the quadratic fit and the contrast threshold 0.03), Section 4.1 (the edge test with r = 10)
- Tony Lindeberg, Feature detection with automatic scale selection, International Journal of Computer Vision 30(2), 79-116, 1998, the sections on blob detection with the scale-normalized Laplacian
- 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 Laplacian, the DoG and the Hessian)
- Richard Szeliski, Computer Vision, Algorithms and Applications, second edition, Springer, 2022, Chapter 7, Section 7.1.1, Feature detectors (scale invariance and the DoG)
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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 832KGB Edit this page History Report an error Markdown