Algorithm Search⌘K

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.

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
Properties
densedeterministicexactnot rotation invariant
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 BB 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 II with WW columns and HH rows; a pixel is (u,v)(u, v), with uu the column and vv the row, and angles grow from the uu axis toward the vv axis. The output is a descriptor D(u,v)D(u, v) 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 BB directions θo=2πo/B\theta_o = 2 \pi o / B, the orientation map is the positive part of the directional derivative,

Go=(cos⁡θo∂I∂u+sin⁡θo∂I∂v)+,(a)+=max⁡(a,0).G_o = \left( \cos \theta_o \frac{\partial I}{\partial u} + \sin \theta_o \frac{\partial I}{\partial v} \right)^+, \qquad (a)^+ = \max(a, 0).

Two opposite directions hold the two signs of the same derivative, so DAISY keeps the polarity of the edges.

Convolved maps. For i=0,…,Q−1i = 0, \dots, Q - 1, the layer ii is GoΣi=GΣi∗GoG_o^{\Sigma_i} = G_{\Sigma_i} * G_o, where GΣG_\Sigma is a Gaussian of standard deviation Σ\Sigma and

Σi=R(i+1)2Q.\Sigma_i = \frac{R (i + 1)}{2 Q}.

Since the convolution of two Gaussians is a Gaussian whose variances add, the layer i+1i + 1 is the layer ii convolved with a Gaussian of standard deviation Σi+12−Σi2\sqrt{\Sigma_{i+1}^2 - \Sigma_i^2}.

Descriptor. Let hΣ(p)=(G1Σ(p),…,GBΣ(p))h_\Sigma(p) = (G_1^\Sigma(p), \dots, G_B^\Sigma(p)) be the histogram at the point pp, and h~\tilde h the same vector scaled to unit length. The ring ii has radius ri=R(i+1)/Qr_i = R (i + 1) / Q and the TT points lj=p+ri(cos⁡θj,sin⁡θj)l_j = p + r_i (\cos \theta_j, \sin \theta_j) with θj=2πj/T\theta_j = 2 \pi j / T. Then

D(p)=(h~Σ0(p),h~Σ0(l0(r0)),…,h~Σ0(lT−1(r0)),…,h~ΣQ−1(lT−1(rQ−1))),D(p) = \left( \tilde h_{\Sigma_0}(p), \tilde h_{\Sigma_0}(l_0(r_0)), \dots, \tilde h_{\Sigma_0}(l_{T-1}(r_0)), \dots, \tilde h_{\Sigma_{Q-1}}(l_{T-1}(r_{Q-1})) \right),

with 1+QT1 + Q T histograms of BB values. The center reads the first layer. The defaults are R=15R = 15, Q=3Q = 3, T=8T = 8 and B=8B = 8, which give 25⋅8=20025 \cdot 8 = 200 values.

The algorithm

  1. DAISY(I, R, Q, T, B, step)
  2. 1(g_u, g_v) ← the image gradient
  3. 2for o = 0, ..., B - 1: G_o ← max(0, cos θ_o g_u + sin θ_o g_v)
  4. 3for 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
  5. 4for each pixel p on the grid of the given step
  6. 5the center histogram ← the B values of layer_0 at p, scaled to unit length
  7. 6for 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
  8. 7D(p) ← the 1 + Q T histograms in order
  9. 8return all D(p)

The paper takes the gradient with the kernels [1,−1][1, -1]; 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 kk steps of 2π/T2 \pi / T, as the paper describes: the ring points move by kk places and, when BB is a multiple of TT, the bins of each histogram move by kB/Tk B / T.

Example

The sigma values. With R=15R = 15 and Q=3Q = 3, the layers have Σ=2.5,5\Sigma = 2.5, 5 and 7.57.5, and the rings have the radii 5,105, 10 and 1515. The incremental convolutions use σ=2.5\sigma = 2.5, then 25−6.25≈4.33\sqrt{25 - 6.25} \approx 4.33, then 56.25−25≈5.59\sqrt{56.25 - 25} \approx 5.59. The last kernel is smaller than a direct one of σ=7.5\sigma = 7.5, and it starts from maps that are already smooth.

A ramp. On the ramp I(u,v)=3u+2vI(u, v) = 3 u + 2 v, away from the border, the gradient is (3,2)(3, 2) at every pixel, so each orientation map is constant and the blur does not change it. With B=8B = 8 the maps are

(3, 3.5355, 2, 0, 0, 0, 0, 0.7071),(3,\ 3.5355,\ 2,\ 0,\ 0,\ 0,\ 0,\ 0.7071),

since for example (3+2)/2≈3.5355(3 + 2)/\sqrt{2} \approx 3.5355 for θ=45°\theta = 45° and (3−2)/2≈0.7071(3 - 2)/\sqrt{2} \approx 0.7071 for θ=315°\theta = 315°. The squared length is 9+12.5+4+0.5=269 + 12.5 + 4 + 0.5 = 26, so every one of the 25 histograms is (0.588,0.693,0.392,0,0,0,0,0.139)(0.588, 0.693, 0.392, 0, 0, 0, 0, 0.139).

A quarter turn. When the image turns by 90 degrees, the gradient turns by 90 degrees, and the map oo of the turned image is the map o−2o - 2 of the original. The descriptor of the turned image, read with k=2k = 2, 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 10−310^{-3} of the largest value away from the border.
  • Each of the 1+QT1 + Q T histograms has unit length unless it is 0, and the descriptor has (1+QT)B(1 + Q T) B 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 B=T=8B = T = 8, maps the descriptor to the descriptor of the turned image read with k=2k = 2.
Proof: Correctness of the DAISY descriptorfull

Pixels are (u,v)(u, v) with uu the column and vv the row. Let g=(gu,gv)g = (g_u, g_v) be the gradient at a pixel, θo=2πo/B\theta_o = 2 \pi o / B, and Go=(cos⁡θo gu+sin⁡θo gv)+G_o = (\cos \theta_o\, g_u + \sin \theta_o\, g_v)^+ with (a)+=max⁡(a,0)(a)^+ = \max(a, 0).

Lemma 1 (orientation maps). GoG_o is the positive part of the derivative of II in the direction θo\theta_o. When BB is even, GoG_o and Go+B/2G_{o + B/2} are never both positive, and Go−Go+B/2G_o - G_{o + B/2} is the directional derivative itself.

Proof. The derivative of II in the unit direction e=(cos⁡θo,sin⁡θo)e = (\cos \theta_o, \sin \theta_o) is e⋅ge \cdot g, which is the argument of the positive part. Since θo+B/2=θo+π\theta_{o + B/2} = \theta_o + \pi, the direction of Go+B/2G_{o + B/2} is −e-e, so its argument is −e⋅g-e \cdot g. For any real aa, a+a^+ and (−a)+(-a)^+ are not both positive and a+−(−a)+=aa^+ - (-a)^+ = a. □\square

Lemma 2 (incremental convolution). Let GsG_s be the Gaussian of standard deviation ss on the plane. For 0≤Σ1<Σ20 \le \Sigma_1 < \Sigma_2 and Σ=Σ22−Σ12\Sigma = \sqrt{\Sigma_2^2 - \Sigma_1^2}, GΣ∗(GΣ1∗f)=GΣ2∗fG_\Sigma * (G_{\Sigma_1} * f) = G_{\Sigma_2} * f for every bounded ff. So the layers of line L3 are the convolutions of the maps with GΣiG_{\Sigma_i}.

Proof. Convolution is associative, so it suffices that GΣ∗GΣ1=GΣ2G_\Sigma * G_{\Sigma_1} = G_{\Sigma_2}. In one dimension the Gaussian of standard deviation ss is the density of a normal variable with variance s2s^2, 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 Σ2+Σ12=Σ22\Sigma^2 + \Sigma_1^2 = \Sigma_2^2. The plane Gaussian is the product of two such factors in uu and vv, so the same holds in the plane. For i=0i = 0 the step is the direct convolution with GΣ0G_{\Sigma_0}, and induction on ii gives the claim for every layer. □\square

In the code the kernels are sampled on the integers, cut at ⌈4σ⌉\lceil 4 \sigma \rceil 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 10−310^{-3} 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 e−x2/(2σ2)e^{-x^2 / (2 \sigma^2)} for x=−r,…,rx = -r, \dots, r are positive and depend only on x2x^2, and they are divided by their sum. A convolution with weights that sum to 1 maps a constant cc to cc, also at the border, where the repeated pixels are equal to cc. A sum of nonnegative values with positive weights is nonnegative. □\square

Lemma 4 (shape and unit histograms). The descriptor has 1+QT1 + Q T histograms of BB 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 QQ rings and TT points, each with one value per map. By Lemma 3 the values are nonnegative. If a histogram hh is not 0, its length nn is positive and h/nh / n has length 1; if it is 0, it stays 0. □\square

Lemma 5 (offset and gain). For a constant cc, the image I+cI + c has the same descriptor as II. For a constant a>0a > 0, the image aIa I has the same descriptor as II.

Proof. The gradient is a difference of pixel values, so it does not change when cc is added to every pixel. For aIa I the gradient is multiplied by aa, and so are the maps, since (ax)+=ax+(a x)^+ = a x^+ for a>0a > 0. The convolutions and the bilinear reads are linear, so every histogram is multiplied by aa, and ah/∥ah∥=h/∥h∥a h / \lVert a h \rVert = h / \lVert h \rVert. □\square

Lemma 6 (a quarter turn). Let NN be the side of a square image II and J(u′,v′)=I(v′,N−1−u′)J(u', v') = I(v', N - 1 - u'), so that the pixel (u,v)(u, v) of II is the pixel (N−1−v,u)(N - 1 - v, u) of JJ. Let B=T=8B = T = 8. Then the descriptor of JJ at (N−1−v,u)(N - 1 - v, u) turned by k=2k = 2 equals the descriptor of II at (u,v)(u, v).

Proof. By the chain rule, and also for the central differences with repeated border pixels, the gradient of JJ at the image of pp is (−gv,gu)(-g_v, g_u), the gradient gg of II at pp turned by +π/2+\pi/2. Then cos⁡θo(−gv)+sin⁡θo gu=cos⁡(θo−π/2) gu+sin⁡(θo−π/2) gv\cos \theta_o (-g_v) + \sin \theta_o\, g_u = \cos(\theta_o - \pi/2)\, g_u + \sin(\theta_o - \pi/2)\, g_v, so the map oo of JJ is the map o−2o - 2 of II, 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 k=2k = 2 the code reads the map o+2o + 2 of JJ, which is the map oo of II. The ring point jj is read at the angle θj+π/2\theta_j + \pi/2 around the image of pp; an offset r(cos⁡(θj+π/2),sin⁡(θj+π/2))=r(−sin⁡θj,cos⁡θj)r(\cos(\theta_j + \pi/2), \sin(\theta_j + \pi/2)) = r(-\sin \theta_j, \cos \theta_j) in JJ is the offset r(cos⁡θj,sin⁡θj)r(\cos \theta_j, \sin \theta_j) in II. So every read value is the same value of the same layer of II, and so is every histogram. □\square

Theorem. The code returns, for each pixel of the grid, the vector D(p)D(p) of 1+QT1 + Q T unit histograms of the convolved orientation maps, the center from the first layer and the ring ii from the layer ii at the radius R(i+1)/QR (i + 1) / Q. 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. □\square

Complexity

The model is the real RAM.

  • Lines L1 and L2 take O(B)O(B) time per pixel.
  • Line L3 does BQB Q separable convolutions. The kernel of a step has radius ⌈4σ⌉=O(R)\lceil 4 \sigma \rceil = O(R), so each takes O(WHR)O(W H R) time.
  • Lines L4 to L7 read (1+QT)B(1 + Q T) B values per pixel, each by a bilinear read in O(1)O(1) time, and scale 1+QT1 + Q T histograms.

The total time is O(WHBQ(R+T))O(W H B Q (R + T)) for a step of 1. The layers take O(WHBQ)O(W H B Q) space. A dense field of descriptors takes (1+QT)B(1 + Q T) B 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 800×600800 \times 600 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 ∣∇I∣|\nabla I| over angles modulo π\pi.
  • 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 RR pixels from the pixel and its blur about 4ΣQ−14 \Sigma_{Q-1} 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 kk ring steps shifts the bins exactly only when BB is a multiple of TT.
  • Memory. Storing all dense descriptors takes (1+QT)B(1 + Q T) B 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.

daisy_descriptor.pyI0RawGitHub
# 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

  1. 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)
  2. 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)
  3. 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.

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