Algorithmadvanced
DAISY descriptor
Also called DAISY.
A dense descriptor that samples convolved orientation maps on concentric rings of points, so that it can be computed at every pixel quickly.
- Solves
- Feature matching
- Time
- O(W H B Q (R + T)) worst · average · best
- Space
- O(W H B Q) extra
- Where
- B = the number of orientation bins; H = the image height in pixels; Q = the number of rings; R = the radius of the outer ring in pixels; T = the number of points on a ring; W = the image width in pixels
- Model
- Real RAM
- Properties
- densedeterministicexactnot rotation invariant
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Engin Tola, Vincent Lepetit, Pascal Fua, 2008
DAISY is a feature descriptor made to be computed at every pixel of an image. Like SIFT, it is built from histograms of gradient orientations, but it gets them in a different way. It first makes one map per orientation, which holds the positive part of the derivative in that direction. It then blurs each map with Gaussian filters of a few sizes. The value of a blurred map at a point is then a histogram bin, so a histogram is a read of maps at one point. The descriptor of a pixel reads such histograms at the pixel and at points on concentric rings around it, with more blur on the outer rings. All the work that nearby descriptors share is done once, in the convolutions, so a dense field of descriptors costs little more than the blur. Tola, Lepetit and Fua built it for stereo matching with a wide baseline.
In plain words
At each pixel, the brightness changes in some direction. Make 8 copies of the image, one for each of 8 directions, and in each copy keep only how much the brightness rises in that direction. Blur each copy a little, more, and much more. Now one blurred copy holds, at each point, how strong the edges near that point are in its direction. To describe a pixel, read the 8 copies at the pixel itself and at 8 points on each of 3 circles around it. The far circles read the copies that are blurred more. Each group of 8 values is scaled to the same length. The 25 groups together are the description.
The problem
The input is a gray image with columns and rows; a pixel is , with the column and the row, and angles grow from the axis toward the axis. The output is a descriptor for every pixel on a grid, which can be compared by the Euclidean distance, as in feature matching or in dense stereo.
Orientation maps. For directions , the orientation map is the positive part of the directional derivative,
Two opposite directions hold the two signs of the same derivative, so DAISY keeps the polarity of the edges.
Convolved maps. For , the layer is , where is a Gaussian of standard deviation and
Since the convolution of two Gaussians is a Gaussian whose variances add, the layer is the layer convolved with a Gaussian of standard deviation .
Descriptor. Let be the histogram at the point , and the same vector scaled to unit length. The ring has radius and the points with . Then
with histograms of values. The center reads the first layer. The defaults are , , and , which give values.
The algorithm
DAISY(I, R, Q, T, B, step)- 1
(g_u, g_v) ← the image gradient - 2
for o = 0, ..., B - 1: G_o ← max(0, cos θ_o g_u + sin θ_o g_v) - 3
for i = 0, ..., Q - 1: layer_i ← layer_{i-1} convolved with the Gaussian of σ = sqrt(Σ_i² - Σ_{i-1}²), with layer_{-1} = G and Σ_{-1} = 0 - 4
for each pixel p on the grid of the given step - 5
the center histogram ← the B values of layer_0 at p, scaled to unit length - 6
for each ring i and each j: the histogram ← the B values of layer_i at p + r_i (cos θ_j, sin θ_j), scaled to unit length - 7
D(p) ← the 1 + Q T histograms in order - 8
return all D(p)
The paper takes the gradient with the kernels ; our code uses central differences, repeats the border pixels for the gradient and the convolutions, and reads the maps between pixels by bilinear interpolation. The paper notes that rounding the points to the nearest pixel works about as well. Our code also builds the descriptor turned by steps of , as the paper describes: the ring points move by places and, when is a multiple of , the bins of each histogram move by .
Example
The sigma values. With and , the layers have and , and the rings have the radii and . The incremental convolutions use , then , then . The last kernel is smaller than a direct one of , and it starts from maps that are already smooth.
A ramp. On the ramp , away from the border, the gradient is at every pixel, so each orientation map is constant and the blur does not change it. With the maps are
since for example for and for . The squared length is , so every one of the 25 histograms is .
A quarter turn. When the image turns by 90 degrees, the gradient turns by 90 degrees, and the map of the turned image is the map of the original. The descriptor of the turned image, read with , is equal to the descriptor of the original at the same point, within rounding.
Correctness
DAISY is a definition, and its use for matching is a benchmark result. The proof in proofs/correctness.md shows that:
- The orientation maps are the positive parts of the directional derivatives, and two opposite maps are never both positive.
- In the continuous case the incremental convolutions give the same layers as direct ones; in the discrete code they agree to about of the largest value away from the border.
- Each of the histograms has unit length unless it is 0, and the descriptor has values.
- A constant offset of the image does not change the descriptor, and a positive gain does not change it either, since each histogram is scaled to unit length.
- A turn of the image by 90 degrees, with , maps the descriptor to the descriptor of the turned image read with .
Proof: Correctness of the DAISY descriptorfull
Pixels are with the column and the row. Let be the gradient at a pixel, , and with .
Lemma 1 (orientation maps). is the positive part of the derivative of in the direction . When is even, and are never both positive, and is the directional derivative itself.
Proof. The derivative of in the unit direction is , which is the argument of the positive part. Since , the direction of is , so its argument is . For any real , and are not both positive and .
Lemma 2 (incremental convolution). Let be the Gaussian of standard deviation on the plane. For and , for every bounded . So the layers of line L3 are the convolutions of the maps with .
Proof. Convolution is associative, so it suffices that . In one dimension the Gaussian of standard deviation is the density of a normal variable with variance , and the density of the sum of two independent variables is the convolution of their densities; the sum of independent normal variables is normal with the sum of the variances, which is . The plane Gaussian is the product of two such factors in and , so the same holds in the plane. For the step is the direct convolution with , and induction on gives the claim for every layer.
In the code the kernels are sampled on the integers, cut at and scaled to sum 1, and the border pixels are repeated, so the identity of Lemma 2 is approximate. The tests check that the incremental and the direct layers agree to of the largest value away from the border.
Lemma 3 (kernels). Each sampled kernel is symmetric and sums to 1, so a constant map is unchanged by the convolution, and the convolution of a nonnegative map is nonnegative.
Proof. The weights for are positive and depend only on , and they are divided by their sum. A convolution with weights that sum to 1 maps a constant to , also at the border, where the repeated pixels are equal to . A sum of nonnegative values with positive weights is nonnegative.
Lemma 4 (shape and unit histograms). The descriptor has histograms of values, and each histogram has unit Euclidean length unless all its values are 0.
Proof. Line L5 adds one histogram and line L6 adds one for each of the rings and points, each with one value per map. By Lemma 3 the values are nonnegative. If a histogram is not 0, its length is positive and has length 1; if it is 0, it stays 0.
Lemma 5 (offset and gain). For a constant , the image has the same descriptor as . For a constant , the image has the same descriptor as .
Proof. The gradient is a difference of pixel values, so it does not change when is added to every pixel. For the gradient is multiplied by , and so are the maps, since for . The convolutions and the bilinear reads are linear, so every histogram is multiplied by , and .
Lemma 6 (a quarter turn). Let be the side of a square image and , so that the pixel of is the pixel of . Let . Then the descriptor of at turned by equals the descriptor of at .
Proof. By the chain rule, and also for the central differences with repeated border pixels, the gradient of at the image of is , the gradient of at turned by . Then , so the map of is the map of , moved by the turn. The Gaussian kernels are symmetric, so the separable convolution with repeated borders commutes with the turn of the grid, and so does bilinear interpolation, including the clamp to the image. With the code reads the map of , which is the map of . The ring point is read at the angle around the image of ; an offset in is the offset in . So every read value is the same value of the same layer of , and so is every histogram.
Theorem. The code returns, for each pixel of the grid, the vector of unit histograms of the convolved orientation maps, the center from the first layer and the ring from the layer at the radius . The descriptor does not change under an offset or a positive gain of the image, and a quarter turn of the image maps it to the turned descriptor of Lemma 6.
Proof. Lines L1 and L2 compute the maps of Lemma 1. Line L3 computes the layers by Lemma 2, up to the sampling of the kernels. Lines L4 to L7 read and scale the histograms at the points of the definition, which gives the shape of Lemma 4. Lemma 5 gives the invariance to an offset and a gain, and Lemma 6 the quarter turn.
Complexity
The model is the real RAM.
- Lines L1 and L2 take time per pixel.
- Line L3 does separable convolutions. The kernel of a step has radius , so each takes time.
- Lines L4 to L7 read values per pixel, each by a bilinear read in time, and scale histograms.
The total time is for a step of 1. The layers take space. A dense field of descriptors takes values per pixel, so the paper keeps the layers and reads a descriptor only when it is needed. The paper reports 3.8 seconds for DAISY against 252 seconds for SIFT for the descriptors at every pixel of an image.
Properties
- Dense. The cost of the shared work is paid once per image and not once per descriptor.
- Polarity. The rectified maps keep the sign of the derivative, unlike a histogram of over angles modulo .
- Normalization per histogram. Each histogram is scaled on its own, so that a part of the descriptor that falls on an occluding object does not change the scale of the other parts.
- Isotropic kernels. The blur is circular, so a turned descriptor needs no new convolutions, only a turn of the sampling points and a shift of the bins.
- Not invariant by default. For stereo, the descriptor is read without a turn; a rotation invariant form needs an orientation from elsewhere.
Variants and improvements
- Turned descriptors. The paper computes the descriptor in several orientations by shifting, which is cheap since the layers stay the same.
- Occlusion masks. For stereo, the paper uses masks that switch off the parts of the descriptor that may be hidden, and it chooses the masks with the depth estimates.
- Other normalizations. The authors note that, outside stereo, a normalization of the whole descriptor may be better.
- Dense SIFT and HOG. SIFT descriptors on a dense grid, and the histogram of oriented gradients, give related dense features, with box or triangle weights in place of the Gaussian layers.
When to use it
Use DAISY when a descriptor is needed at every pixel, as in wide-baseline stereo, dense correspondence, or optical flow with large motions. For sparse keypoints, SIFT or SURF give a scale and an orientation as well; for short, very fast codes, binary descriptors are better.
Pitfalls
- The center layer. The center histogram reads the first, least blurred layer, not a layer of its own.
- Border. The outer ring reaches pixels from the pixel and its blur about more; near the border the replicated pixels change the values.
- Flat regions. A histogram with no gradient is 0 and stays 0, and a weak one is scaled up to unit length, which makes noise look like structure.
- Turning with few bins. A turn by ring steps shifts the bins exactly only when is a multiple of .
- Memory. Storing all dense descriptors takes values per pixel, 200 by default.
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/daisy-descriptor/. The authors are listed in prov/HGVST3.jsonl.
"""DAISY: a dense descriptor from convolved orientation maps (Tola, Lepetit and Fua).
An image is a list of H rows of W numbers; pixel (u, v) is img[v][u], with u
the column (to the right) and v the row (down). Angles grow from the u axis
toward the v axis.
1. Gradients by central differences, with the border pixels repeated.
2. B orientation maps G_o = max(0, cos(t_o) g_u + sin(t_o) g_v), t_o = 2 pi o / B.
3. Each map is convolved with Gaussians of sigma_i = R (i + 1) / (2 Q) for
i = 0, ..., Q - 1, incrementally: the layer i + 1 is the layer i convolved
with sigma = sqrt(sigma_{i+1}^2 - sigma_i^2).
4. At a pixel, the descriptor has 1 + Q T histograms of B values: one at the
center from layer 0, and T on each ring i of radius R (i + 1) / Q from
layer i, read by bilinear interpolation. Each histogram is scaled to length
1 on its own. The defaults R = 15, Q = 3, T = 8, B = 8 give 200 values.
Turning the descriptor by k steps of 2 pi / T moves the ring points by k and,
when B is a multiple of T, the histogram bins by k B / T.
"""
import math
from typing import List, Sequence
Image = Sequence[Sequence[float]]
Map = List[List[float]]
def gradients(img: Image):
h, w = len(img), len(img[0])
gu = [[(img[v][min(u + 1, w - 1)] - img[v][max(u - 1, 0)]) / 2.0 for u in range(w)] for v in range(h)]
gv = [[(img[min(v + 1, h - 1)][u] - img[max(v - 1, 0)][u]) / 2.0 for u in range(w)] for v in range(h)]
return gu, gv # @line L1
def orientation_maps(img: Image, bins: int = 8) -> List[Map]:
gu, gv = gradients(img)
h, w = len(img), len(img[0])
maps = []
for o in range(bins):
c, s = math.cos(2 * math.pi * o / bins), math.sin(2 * math.pi * o / bins)
maps.append([[max(0.0, c * gu[v][u] + s * gv[v][u]) for u in range(w)] for v in range(h)]) # @line L2
return maps
def gaussian_kernel(sigma: float) -> List[float]:
r = max(1, int(math.ceil(4 * sigma)))
k = [math.exp(-(x * x) / (2 * sigma * sigma)) for x in range(-r, r + 1)]
s = sum(k)
return [x / s for x in k]
def convolve(m: Map, sigma: float) -> Map:
"""Separable Gaussian convolution with the border pixels repeated."""
k = gaussian_kernel(sigma)
r = len(k) // 2
h, w = len(m), len(m[0])
tmp = [[sum(k[i] * row[min(max(u + i - r, 0), w - 1)] for i in range(len(k))) for u in range(w)] for row in m]
return [[sum(k[i] * tmp[min(max(v + i - r, 0), h - 1)][u] for i in range(len(k))) for u in range(w)]
for v in range(h)]
def sigmas(R: float = 15.0, Q: int = 3) -> List[float]:
return [R * (i + 1) / (2 * Q) for i in range(Q)]
def layers(img: Image, R: float = 15.0, Q: int = 3, bins: int = 8) -> List[List[Map]]:
"""layers[i][o]: the map o convolved with sigma_i, built incrementally."""
maps = orientation_maps(img, bins)
out = []
prev = 0.0
cur = maps
for s in sigmas(R, Q):
cur = [convolve(m, math.sqrt(s * s - prev * prev)) for m in cur] # @line L3
out.append(cur)
prev = s
return out
def bilinear(m: Map, x: float, y: float) -> float:
h, w = len(m), len(m[0])
x = min(max(x, 0.0), w - 1.0)
y = min(max(y, 0.0), h - 1.0)
x0, y0 = min(int(x), w - 2), min(int(y), h - 2)
fx, fy = x - x0, y - y0
return ((1 - fy) * ((1 - fx) * m[y0][x0] + fx * m[y0][x0 + 1])
+ fy * ((1 - fx) * m[y0 + 1][x0] + fx * m[y0 + 1][x0 + 1]))
def _unit(h: List[float]) -> List[float]:
n = math.sqrt(sum(x * x for x in h))
return [x / n for x in h] if n > 0 else h
def describe(lay: List[List[Map]], u: float, v: float, R: float = 15.0, T: int = 8, k: int = 0) -> List[float]:
"""The descriptor at (u, v), turned by k steps of 2 pi / T."""
Q, bins = len(lay), len(lay[0])
if k % T and bins % T:
raise ValueError("turning needs a number of bins that is a multiple of T")
shift = k * bins // T
hist = [lay[0][(o + shift) % bins] for o in range(bins)]
out = _unit([bilinear(m, u, v) for m in hist]) # @line L5
for i in range(Q):
r = R * (i + 1) / Q
maps = [lay[i][(o + shift) % bins] for o in range(bins)]
for j in range(T):
a = 2 * math.pi * ((j + k) % T) / T
x, y = u + r * math.cos(a), v + r * math.sin(a)
out.extend(_unit([bilinear(m, x, y) for m in maps])) # @line L6
return out # @line L7
def daisy(img: Image, step: int = 1, R: float = 15.0, Q: int = 3, T: int = 8, bins: int = 8):
"""Dense descriptors on the grid of the given step: {(u, v): descriptor}."""
lay = layers(img, R, Q, bins)
h, w = len(img), len(img[0])
out = {}
for v in range(0, h, step): # @line L4
for u in range(0, w, step):
out[(u, v)] = describe(lay, u, v, R, T)
return out # @line L8
test_daisy_descriptor.py 90 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/daisy-descriptor/. The authors are listed in prov/HGVST3.jsonl.
import math
import random
from daisy_descriptor import bilinear, convolve, daisy, describe, gaussian_kernel, layers, orientation_maps, sigmas
def random_image(seed, w, h):
rng = random.Random(seed)
return [[rng.randint(0, 255) for _ in range(w)] for _ in range(h)]
def close(a, b, tol):
return len(a) == len(b) and all(abs(x - y) <= tol for x, y in zip(a, b))
def test_length_and_unit_histograms():
img = random_image(1, 32, 32)
lay = layers(img)
d = describe(lay, 16, 15)
assert len(d) == 200 == (1 + 3 * 8) * 8
for k in range(25):
n = math.sqrt(sum(x * x for x in d[8 * k:8 * k + 8]))
assert abs(n - 1.0) < 1e-12
assert sigmas() == [2.5, 5.0, 7.5]
def test_orientation_maps_on_a_ramp():
img = [[3.0 * u + 2.0 * v for u in range(10)] for v in range(10)]
maps = orientation_maps(img, 8)
for o in range(8):
a = 2 * math.pi * o / 8
assert abs(maps[o][5][5] - max(0.0, 3 * math.cos(a) + 2 * math.sin(a))) < 1e-12
# Opposite maps hold the two rectified halves of the directional derivative.
img = random_image(2, 12, 12)
maps = orientation_maps(img, 8)
for o in range(4):
for v in range(12):
for u in range(12):
assert maps[o][v][u] == 0.0 or maps[o + 4][v][u] == 0.0
def test_kernel_and_constant_maps():
for s in (0.5, 1.0, 2.5, 3.7):
k = gaussian_kernel(s)
assert abs(sum(k) - 1.0) < 1e-12 and k == k[::-1]
flat = [[5.0] * 9 for _ in range(7)]
assert all(abs(x - 5.0) < 1e-12 for row in convolve(flat, 2.0) for x in row)
def test_incremental_convolution_matches_direct_convolution_inside():
img = random_image(3, 56, 56)
maps = orientation_maps(img, 4)
lay = layers(img, R=6.0, Q=3, bins=4)
for i, s in enumerate(sigmas(6.0, 3)):
direct = convolve(maps[1], s)
top = max(direct[v][u] for v in range(20, 36) for u in range(20, 36))
err = max(abs(direct[v][u] - lay[i][1][v][u]) for v in range(20, 36) for u in range(20, 36))
assert err < 1e-3 * top
def test_rotation_by_90_degrees_permutes_the_descriptor():
img = random_image(4, 28, 28)
rot = [[img[27 - u][v] for u in range(28)] for v in range(28)]
a, b = layers(img, R=6.0), layers(rot, R=6.0)
for u, v in [(14, 11), (9, 16), (18, 18)]:
# The pixel (u, v) of img is the pixel (27 - v, u) of rot; a quarter turn is 2 steps of 45 degrees.
assert close(describe(b, 27 - v, u, R=6.0, k=2), describe(a, u, v, R=6.0), 1e-9)
assert not close(describe(b, 27 - 11, 14, R=6.0), describe(a, 14, 11, R=6.0), 1e-3)
def test_offset_and_gain():
img = random_image(5, 28, 28)
base = describe(layers(img, R=6.0), 12, 15, R=6.0)
assert describe(layers([[x + 30 for x in row] for row in img], R=6.0), 12, 15, R=6.0) == base
assert close(describe(layers([[3 * x for x in row] for row in img], R=6.0), 12, 15, R=6.0), base, 1e-12)
def test_bilinear_and_dense_grid():
ramp = [[2.0 * u - v for u in range(8)] for v in range(8)]
assert abs(bilinear(ramp, 3.25, 4.5) - (6.5 - 4.5)) < 1e-12
assert bilinear(ramp, 2, 5) == ramp[5][2]
img = random_image(6, 24, 24)
dense = daisy(img, step=8, R=6.0, Q=2, T=4, bins=4)
assert sorted(dense) == [(u, v) for u in (0, 8, 16) for v in (0, 8, 16)]
lay = layers(img, 6.0, 2, 4)
assert dense[(8, 16)] == describe(lay, 8, 16, 6.0, 4)
assert len(dense[(0, 0)]) == (1 + 2 * 4) * 4
History
Tola, Lepetit and Fua, at EPFL, presented DAISY at CVPR 2008 as a fast local descriptor for dense matching and gave the full form, with the stereo method and its occlusion handling, in IEEE TPAMI in 2010. They named it for its shape, which looks like a flower. The design takes the histograms of SIFT and GLOH and replaces the sums over cells by Gaussian convolutions of orientation maps, with larger kernels away from the center, as the geometric blur of Berg and Malik recommends.
References
- Engin Tola, Vincent Lepetit and Pascal Fua, DAISY, an efficient dense descriptor applied to wide-baseline stereo, IEEE Transactions on Pattern Analysis and Machine Intelligence 32(5), 815-830, 2010, Section III (the orientation maps, the incremental convolution, Equation 1 for the histograms, the definition of the descriptor, Equation 2 for the sigma values, the ring radii, the rotation by shifting, Table I for the parameters, Table II for the times)
- Engin Tola, Vincent Lepetit and Pascal Fua, A fast local descriptor for dense matching, IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 1-8, 2008, the whole paper (the first form of the descriptor)
- David G. Lowe, Distinctive image features from scale-invariant keypoints, International Journal of Computer Vision 60(2), 91-110, 2004, the section on the local image descriptor (the SIFT histograms that DAISY replaces by convolutions)
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 HGVST3 Edit this page History Report an error Markdown