Skip to content

Marr-Hildreth

Fact Value
Also called Marr-Hildreth edge detector, LoG edge detector
Status Implemented and tested
Family Edge detection and boundary analysis
Engine Browser
Type Nonlinear, spatial, LoG and sign change test
Output Mask
Operator shown as algorithm (exact)
Support radius floor(4 sigma + 0.5) + 1
Code web/src/core/filters/edges/zero-crossing.ts, marrHildrethFilter
Operator code web/src/core/filters/edges/zero-crossing.ts, marrHildrethFilter
Channels Brightness only, RGB

Overview

The Marr-Hildreth detector finds edges as the zero crossings of the Laplacian of Gaussian. The Gaussian sets the scale and removes noise, and the Laplacian crosses zero where the brightness changes fastest. The result is a mask of thin, closed edge lines.

Three panels: bright disks on a dark background, the Marr-Hildreth edges with threshold 0, which include loops from faint shading, and with threshold 2, which keep only the disk outlines. Three panels: bright disks on a dark background, the Marr-Hildreth edges with threshold 0, which include loops from faint shading, and with threshold 2, which keep only the disk outlines.
With threshold 0 even faint shading makes edge loops. A small threshold keeps the real outlines.

How it works

  1. Apply the Laplacian of Gaussian with the chosen sigma.
  2. Find negative pixels with a positive neighbor.
  3. Mark them when the jump is above the threshold.

Mathematical foundation

\[ L = \nabla^2 (G_{\sigma} * I), \qquad E(p) = 255 \;\text{ if }\; L(p) < 0 \;\text{ and }\; \exists\, q \in N_4(p) : L(q) > 0,\; L(q) - L(p) > T \]

The formula shows the default parameter values.

where

  • \(L\): The Laplacian of Gaussian
  • \(T\): The threshold

Marr and Hildreth proposed to smooth with a Gaussian and look for the zero crossings of the Laplacian. At an edge the first derivative has its extremum, so the second derivative crosses zero. The LoG is the one in this catalog, truncated at 4 sigma, and the crossing rule marks the negative side, as in the zero-crossing detector.

Marr and Hildreth argued that edges should be found at several scales, each with a Gaussian of a different size, and that the zero crossings of the Laplacian mark them. The Laplacian is rotation invariant, so edges in all directions are treated the same. Zero crossings form closed curves, which is both a strength and a weakness: gentle shading also produces closed loops, so a threshold on the jump is needed.

Kernel or operator

There is no single kernel. The Inspector shows the two steps. The LoG kernel is on the Laplacian of Gaussian page.

Algorithm

  1. Extend the image by the full support with the border mode.
  2. Compute the Laplacian of Gaussian.
  3. Mark each negative pixel with a positive 4-neighbor and a jump above the threshold.
  4. Cut the extension off and write 255 at marked pixels.

Parameters

Parameter Default Values Meaning
Sigma sigma 2 0.5 to 10 px The sigma of the Laplacian of Gaussian.
Threshold threshold 0 0 to 50 The smallest jump of the LoG across a crossing that counts.
Output mapping outputMapping Clip to 0 to 255 Absolute value, Offset by 128, Stretch to full range, Clip to 0 to 255 How signed results, such as gradients, become 8-bit pixel values.
Border mode border Reflect 101 (default) Reflect 101 (default), Reflect, Replicate, Constant (zero), Wrap How pixels outside the image are filled when the window reaches past the edge.
Channels channelScope Brightness only RGB, Brightness only Which part of the color image the filter changes.

Implementation

marrHildrethFilter in web/src/core/filters/edges/zero-crossing.ts extends the plane once by the LoG support plus one pixel with the border mode, runs the LoG filter and the zero-crossing rule, and cuts the extension off. The filter runs in the browser engine, in Web Workers, through the shared filter framework in web/src/core/filters/run.ts, which handles the border mode, the channel scope, alpha and the output mapping. By default it works on luma and gives a gray mask.

Worked example

x 29 30 31 32 33 34
Input 40 40 40 215 215 215
LoG + 128 141 148 138 118 108 115
Edge mask 0 0 0 255 0 0

A step edge with sigma 1.5. The LoG, shown with the offset mapping, is above 128 on the dark side and below it on the bright side. The first pixel below 128, next to one above, is marked with 255. It is the first bright pixel of the step.

Complexity

  • Time: \(O(N\,\sigma)\)
  • Memory: \(O(N)\)

N is the number of pixels per channel. The LoG costs four 1D passes of about 8 sigma taps.

Artifacts and limitations

Limitations

  • Without a threshold, noise and gentle shading create many false edges.
  • Corners are rounded at large sigmas.

Artifacts

  • Spaghetti-like loops in flat areas when the threshold is 0.

Tests

The reference runs scipy.ndimage.gaussian_laplace on the extended plane and applies the same rule. Before it is used, the script checks that a step edge is marked on its bright side, the negative side of the LoG, and nowhere else. The test covers two sigma and threshold settings for all five border modes.

References

  • Marr, D. and Hildreth, E. Theory of edge detection. Proceedings of the Royal Society of London, Series B 207(1167), 187 to 217, 1980. DOI 10.1098/rspb.1980.0020.
  • Gonzalez, R. C. and Woods, R. E. Digital Image Processing, 4th edition. Pearson, 2018. Section 10.2, the Marr-Hildreth edge detector.