Skip to content

DoG blob detection

Fact Value
Also called DoG keypoint detection, Difference of Gaussians blobs
Status Implemented and tested
Family Texture, corners, blobs and features
Engine Science engine
Type Nonlinear, spatial, difference of Gaussians extrema
Output Features
Operator shown as algorithm (exact)
Support radius global
Code engine/src/pixelnexus_engine/filters/blobs.py, blob_dog_filter
Operator code engine/src/pixelnexus_engine/filters/blobs.py, blob_representation
Packages scikit-image

Overview

DoG blob detection finds round spots and their sizes with differences of Gaussians. Each blur is subtracted from the next wider one. This is close to the scale-normalized Laplacian of Gaussian, and cheaper, since each blur is used twice. SIFT finds its keypoints in the same scale space. The image does not change. The blobs go to the Features panel and are drawn on the canvas. The filter runs in the PixelNexus engine, with scikit-image.

Four panels of the Disks test image. With the defaults, a ring marks each of the six disks, some a little smaller than the disk, and the single bright pixels get none. With the smallest sigma at 3, some rings change size, since the scales start at another sigma. On a noisy copy, the six disks still get their rings. Four panels of the Disks test image. With the defaults, a ring marks each of the six disks, some a little smaller than the disk, and the single bright pixels get none. With the smallest sigma at 3, some rings change size, since the scales start at another sigma. On a noisy copy, the six disks still get their rings.
The Disks test image, and the blobs found with the defaults, with the smallest sigma at 3, and on a noisy copy. Each blob is drawn as a ring of its radius.

How it works

  1. Take the luma from 0 to 1, negated for dark blobs.
  2. Blur it with Gaussians whose sigmas grow by the ratio k.
  3. Subtract each blur from the one before and divide by k - 1.
  4. Keep the points that beat their 26 neighbors in position and scale and reach the threshold.
  5. Remove the smaller of two blobs that overlap too much, and report the rest.

Mathematical foundation

\[ R_{\sigma_i}(x) = \frac{(G_{\sigma_i} - G_{\sigma_{i+1}}) * I}{k - 1}(x), \qquad \sigma_i = \sigma_{\min} k^i, \qquad r = \sqrt{2}\, \sigma_i,\quad k = 1.6 \]

The formula shows the default parameter values.

where

  • \(I\): The luma from 0 to 1, or 1 minus it for dark blobs
  • \(G_\sigma\): A Gaussian of sigma
  • \(k\): The sigma ratio
  • \(r\): The radius of the blob

The difference of two Gaussian blurs whose sigmas differ by the ratio k is close to the scale-normalized Laplacian of Gaussian, times k - 1. So dividing by k - 1 gives a response close to the one of LoG blob detection, at much less cost, since each blur is used twice. The sigmas grow by the ratio k from the smallest sigma until they pass the largest. Then scikit-image keeps the points that are the largest of their 3 x 3 x 3 neighbors in position and scale and reach the threshold. Then it prunes blobs that overlap too much. The blob's sigma is the smaller of the two sigmas of its difference. The score is R at the peak.

A Gaussian blur obeys the heat equation: its change with sigma is sigma times its Laplacian. So the difference of two blurs whose sigmas differ by the ratio k is about (k - 1) sigma^2 times the Laplacian of the blur. Dividing by k - 1 gives a response close to the scale-normalized Laplacian of Gaussian, as Lowe used for SIFT.

The sigmas start at the smallest sigma and grow by the ratio k until they pass the largest. A point is a blob when it is the largest of its 26 neighbors in position and scale and reaches the threshold. Overlapping blobs are pruned as in LoG blob detection. The blob's sigma is the smaller of the two in its difference, and its radius is sqrt(2) sigma. Since the sigmas grow by a factor, the sizes come in coarse steps for large blobs.

Kernel or operator

The Inspector asks the engine for the stages with the current settings. They are the input luma, the response with the list of scales, the peak rule with the threshold, and the pruning rule with the overlap.

Parameters

Parameter Default Values Meaning
Blobs blobs Bright blobs Bright blobs, Dark blobs Whether the blobs are brighter or darker than their surroundings. Dark blobs are found as bright blobs of the negated luma.
Smallest sigma minSigma 1 0.5 to 50 px The smallest scale. Blobs smaller than the matching radius are missed.
Largest sigma maxSigma 50 1 to 100 px The largest scale. scikit-image uses 50. If it is below the smallest sigma, only the smallest is used.
Sigma ratio sigmaRatio 1.6 1.1 to 3 The ratio k between neighboring scales. scikit-image uses 1.6 by default.
Threshold threshold 0.2 0 to 1 The smallest response a blob needs, for an image from 0 to 1. scikit-image uses 0.5, which finds nothing on the Disks image. 0.2 finds its six disks.
Overlap overlap 0.5 0 to 1 Of two blobs whose areas overlap by more than this share, the smaller goes. 1 keeps all.

Implementation

blob_dog_filter in engine/src/pixelnexus_engine/filters/blobs.py takes the luma from 0 to 1 and calls skimage.feature.blob_dog. For dark blobs it uses 1 minus the luma. The score is the difference of the two blurs of skimage.filters.gaussian at the peak, divided by k - 1, as scikit-image computes it. The default threshold is 0.2, not the 0.5 of scikit-image, which finds no blob on the Disks image.

The result is a table, not an image. It has one row per blob, with x and y, the radius, sigma and the score. The x and y columns give the column and row of the center pixel, counted from 0 at the top left. The Features panel shows the table, exports it as CSV, and switches the drawing on the canvas. With a selection, the detector still looks at the whole image, and only the blobs whose center lies in the selection are kept. The Feature viewer in the Learn panel runs the detector on the patch around the probe.

Worked example

Disk radius (px) Found radius (px) Center off by (px) Score
48 38.0 1.0 0.4132
24 23.7 0.0 0.3860
12 9.3 0.0 0.4113
6 5.8 0.0 0.3860
72 60.7 0.0 0.4073
36 23.7 1.0 0.3809

The six disks of the Disks test image at 512 x 512, and the nearest blob that DoG blob detection finds with the defaults. A disk counts as not found when no blob lies within half its radius. With the defaults it finds 6 blobs in all, and 0 of them are not at a disk: the four single bright pixels, or false blobs. On a copy with Gaussian noise of sigma 12 it finds 6.

Complexity

  • Time: \(O(S N sigma_max)\)
  • Memory: \(O(S N)\)

N is the number of pixels and S the number of scales, about log(sigma_max / sigma_min) / log(k).

Artifacts and limitations

Limitations

  • The sizes come in steps of the ratio k, so they are coarse for large blobs.
  • On the Disks image it misses the single bright pixels, which the Laplacian of Gaussian finds.
  • The threshold has another scale than in LoG blob detection.

Artifacts

  • A low threshold gives rings of false blobs around large bright shapes.

Tests

The detector must return what skimage.feature.blob_dog returns. On the Disks image, it must find the six disks within 2 pixels. Dark blobs must be the bright blobs of the negated image. A flat image must have no blobs. The engine API tests check that the table arrives as JSON, and the stages of the representation.

References

  • Lowe, D. G. Distinctive image features from scale-invariant keypoints. International Journal of Computer Vision 60(2), 91 to 110, 2004. DOI 10.1023/B:VISI.0000029664.99615.94.
  • scikit-image documentation, skimage.feature.blob_dog.