Skip to content

Morphological reconstruction

Fact Value
Also called Reconstruction by dilation, Reconstruction by erosion, h-dome
Status Implemented and tested
Family Morphological filters
Engine Browser
Type Nonlinear, spatial, geodesic reconstruction
Output Image
Operator shown as algorithm (exact)
Support radius global
Code web/src/core/filters/morphology/reconstruction.ts, reconstructionFilter
Operator code web/src/core/filters/morphology/reconstruction.ts, reconstruct
Channels RGB, Brightness only

Overview

Morphological reconstruction lets a marker grow under the image until nothing changes. Every bright region the marker touches comes back, up to the marker's height, and keeps its exact outline. Here the marker is the image moved down by h, so every peak loses its top h levels and smaller peaks vanish. Reconstruction by erosion does the same for dark valleys.

Two panels: noisy bright disks, and the reconstruction with h 60, in which the disks and white specks are dimmer and the dark background is unchanged. Two panels: noisy bright disks, and the reconstruction with h 60, in which the disks and white specks are dimmer and the dark background is unchanged.
Reconstruction by dilation with h = 60 on noisy disks. Every bright peak loses its top 60 levels, so the disks and the white specks are dimmer. The dark background stays as it was.

How it works

  1. Move the image down by h to get the marker.
  2. Let the marker grow, one neighbor at a time, but never above the image.
  3. Stop when nothing changes.

Mathematical foundation

\[ R^{\delta}_f(J) = \lim_{k \to \infty} \delta^{(k)}_f(J),\qquad \delta^{(1)}_f(J) = \delta_N(J) \wedge f \]

The formula shows the default parameter values.

where

  • \(f\): The image itself as the mask
  • \(J\): The marker
  • \(N\): The 3 x 3 cross or square

J is the marker, here the image moved down by h, and f is the mask, the image itself. Each geodesic step dilates J with the 3 x 3 element N and takes the minimum with f, so J never rises above f. Repeating until nothing changes gives the reconstruction. By erosion is the same with the roles of minimum and maximum swapped. The marker is first clamped below (or above) the mask. The filter uses the hybrid algorithm of Vincent and matches skimage.morphology.reconstruction.

A geodesic dilation dilates the marker with the 3 x 3 element and takes the minimum with the image, the mask. Repeating it until nothing changes gives the reconstruction. Because growth follows connected paths, a region is either restored or not, and its borders never move. With the marker f - h, the result removes the h-domes, the top h levels of every peak, and subtracting it from the image gives those domes.

Kernel or operator

There is no kernel. The Inspector lists the marker and the reconstruction with the current h and connectivity.

Algorithm

  1. Build the marker, the image moved down by h for dilation or up for erosion.
  2. Scan in raster order, then in reverse order, spreading the marker under the mask.
  3. Spread the rest with a queue until nothing changes.

Parameters

Parameter Default Values Meaning
Method method By dilation (bright parts) By dilation (bright parts), By erosion (dark parts) Whether the marker grows up under the image or shrinks down over it.
Height h h 20 0 to 255 The marker is the image moved down by h for dilation, or up by h for erosion.
Neighbors connectivity 8 neighbors 8 neighbors, 4 neighbors Which pixels count as joined when the reconstruction spreads.
Channels channelScope RGB RGB, Brightness only Which part of the color image the filter changes.

Implementation

The function reconstruct in web/src/core/filters/morphology/reconstruction.ts uses the hybrid algorithm of Vincent: a raster scan, an anti-raster scan, and a queue for the pixels that still need to spread. Reconstruction by erosion runs the same code on negated values. It is a global filter. Reconstruction can reach across the whole image, so the filter always runs on the whole image in one tile, and a selection is cut out of the result. The filter runs in the browser engine through the shared filter framework in web/src/core/filters/run.ts, which handles the channel scope and alpha.

Worked example

x 0 1 2 3 4 5 6 7 8 9
Input 10 10 40 10 10 90 120 90 10 10
Reconstruction, h 50 10 10 10 10 10 70 70 70 10 10

The marker is the row minus 50. The peak of 40 rises only 30 above its base, less than h, so the marker never reaches above the base there and the peak is flattened to 10. The peak of 120 rises 110, so it comes back as a plateau at 70, 50 below its top. The base is restored to 10, since the marker spreads to it from the large peak.

Complexity

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

N is the number of pixels per channel. Each pixel is visited a few times.

Artifacts and limitations

Limitations

  • A single marker pixel brings back a whole region, so noise in the marker matters.

Artifacts

  • Flat plateaus where peaks were cut.

Tests

The reference uses skimage.morphology.reconstruction with the 3 x 3 cross or square. Before the cases are written, the script checks that plain iterated geodesic dilation gives the same result as scikit-image. The cases cover both methods and both connectivities.

References