Skip to content

LoG blob detection

Fact Value
Also called Laplacian of Gaussian blobs, Blob detection
Status Implemented and tested
Family Texture, corners, blobs and features
Engine Science engine
Type Nonlinear, spatial, scale-normalized LoG extrema
Output Features
Operator shown as algorithm (exact)
Support radius global
Code engine/src/pixelnexus_engine/filters/blobs.py, blob_log_filter
Operator code engine/src/pixelnexus_engine/filters/blobs.py, blob_representation
Packages scikit-image

Overview

LoG blob detection finds round spots and their sizes. It blurs the image with Gaussians of many sizes and takes the Laplacian of each blur, scaled so the sizes can be compared. A blob is a point where this response is larger than at all its neighbors, in place and in size. Each blob comes with its center, radius and score. 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 fits each of the six disks and a small ring marks each of the four single bright pixels. With the smallest sigma at 3, the small rings at the single pixels are gone. On a noisy copy, the disks and the single pixels still get their rings. Four panels of the Disks test image. With the defaults, a ring fits each of the six disks and a small ring marks each of the four single bright pixels. With the smallest sigma at 3, the small rings at the single pixels are gone. On a noisy copy, the disks and the single pixels 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. Filter it with the Laplacian of Gaussian at each scale, times minus sigma squared.
  3. Keep the points that beat their 26 neighbors in position and scale and reach the threshold.
  4. Remove the smaller of two blobs that overlap too much.
  5. Report the center, the radius sqrt(2) sigma, sigma and the response.

Mathematical foundation

\[ R_\sigma(x) = -\sigma^2\, \nabla^2 (G_\sigma * I)(x), \qquad (x, \sigma) \text{ is a blob if } R_\sigma(x) = \max_{3 \times 3 \times 3} R \ge T, \qquad r = \sqrt{2}\, \sigma,\quad T = 0.2 \]

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
  • \(\nabla^2\): The Laplacian, the sum of the second derivatives
  • \(r\): The radius of the blob
  • \(T\): The threshold

The Laplacian of a Gaussian blur is strongly negative in the middle of a bright blob whose size matches the blur. Its size shrinks as sigma grows, so it is multiplied by sigma^2 to make the scales comparable, the scale normalization of Lindeberg. The response R then has a peak at the center of each blob, at the scale that matches its size. For a disk of radius r, that scale is about sigma = r / sqrt(2). Here scikit-image builds R at evenly spaced scales. It 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 score is R at the peak.

The Laplacian of a Gaussian blur is strongly negative in the middle of a bright blob whose size matches the blur. As the blur grows, all second derivatives shrink, so a raw comparison over sizes would always favor small blurs. Lindeberg showed that multiplying by sigma^2 makes the sizes comparable. With this scale normalization, the response of a disk of radius r peaks at sigma = r / sqrt(2), so the radius of a blob is sqrt(2) sigma.

scikit-image builds the response at evenly spaced scales, or at scales evenly spaced in log sigma. A point is a blob when it is the largest of its 26 neighbors in the 3 x 3 x 3 block of position and scale, and reaches the threshold. Of two blobs whose areas overlap by more than the overlap limit, the smaller goes. The score in the table is the response at the peak.

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.
Number of scales numSigma 10 2 to 50 How many scales are tried between the smallest and the largest sigma.
Logarithmic scales logScale off On or off Space the scales evenly in log sigma instead of in sigma, so small scales are tried more closely.
Threshold threshold 0.2 0 to 1 The smallest response a blob needs, for an image from 0 to 1. scikit-image uses 0.2.
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_log_filter in engine/src/pixelnexus_engine/filters/blobs.py takes the luma from 0 to 1 and calls skimage.feature.blob_log. For dark blobs it uses 1 minus the luma. The score comes from scipy.ndimage.gaussian_laplace at the blob's scale, as scikit-image computes it.

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 47.6 0.0 0.5483
24 24.5 0.0 0.5474
12 9.1 0.0 0.4559
6 9.1 0.0 0.4135
72 70.7 0.0 0.5471
36 39.9 1.0 0.5375

The six disks of the Disks test image at 512 x 512, and the nearest blob that LoG 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 10 blobs in all, and 4 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 13.

Complexity

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

N is the number of pixels and S the number of scales. Each Gaussian Laplacian costs O(N sigma) with separable kernels.

Artifacts and limitations

Limitations

  • Slow for large sigma, since every scale is a full Gaussian filter.
  • The size is only as fine as the scales. With 10 scales from 1 to 50, they are 5.4 px apart.
  • Elongated shapes give several blobs or none.

Artifacts

  • Single bright pixels and noise give blobs at the smallest scale.

Tests

The detector must return what skimage.feature.blob_log returns, with the radius sqrt(2) sigma and the scores in falling order. On the Disks image, it must find each disk within 2 pixels, with a radius within half a scale step, and the four single bright pixels at sigma 1. With the smallest sigma at 3, only the six disks remain. Dark blobs must be the bright blobs of the negated image. The score must be minus sigma squared times the Gaussian Laplacian at the peak. 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

  • Lindeberg, T. Feature detection with automatic scale selection. International Journal of Computer Vision 30(2), 79 to 116, 1998. DOI 10.1023/A:1008045108935.
  • scikit-image documentation, skimage.feature.blob_log.