Skip to content

Closing by reconstruction

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

Overview

Closing by reconstruction dilates the image, then reconstructs the dilation by erosion over the image. Dark objects the element does not fit into fill in, and every other dark object comes back with its exact shape.

Three panels: noisy bright disks, the plain closing, which fills the black specks, and the closing by reconstruction, which also fills them. Three panels: noisy bright disks, the plain closing, which fills the black specks, and the closing by reconstruction, which also fills them.
Closing and closing by reconstruction with disk 2. Both fill the black specks in the background, and the reconstruction keeps the dark background exact.

How it works

  1. Dilate the image with the structuring element.
  2. Reconstruct the dilation by erosion over the image.

Mathematical foundation

\[ \varphi_R(f) = R^{\varepsilon}_f(f \oplus B) \]

The formula shows the default parameter values.

where

  • \(B\): The structuring element
  • \(R^{\varepsilon}_f\): Reconstruction by erosion over f

The dilation fills every dark object the element does not fit into. Reconstruction by erosion over the image then brings back every dark object that kept at least one pixel, with its exact shape.

The dilation decides which dark objects are large enough: those that keep at least one pixel. Reconstruction by erosion then restores those dark objects completely. The result is a closing, and a connected operator that never moves an edge.

Kernel or operator

There is no single kernel. The Inspector lists the dilation and the reconstruction, and the element is on the Dilation page.

Algorithm

  1. Extend the image with the border mode and dilate it with the element, then cut the extension off.
  2. Reconstruct the dilation by erosion over the image.

Parameters

Parameter Default Values Meaning
Structuring element element disk 1 Disk, rectangle, ellipse, cross, diamond, line or custom, with sizes The element of the first step. Bright or dark details it does not fit into are removed.
Iterations iterations 1 1 to 10 How many times the first step runs.
Neighbors connectivity 8 neighbors 8 neighbors, 4 neighbors Which pixels count as joined when the reconstruction spreads.
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 RGB RGB, Brightness only Which part of the color image the filter changes.

Implementation

The filter extends the image with the border mode for the dilation, cuts the extension off, and then reconstructs. 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 120 120 90 120 120 40 10 40 120 120
Closing by reconstruction 120 120 120 120 120 40 40 40 120 120

The row turned upside down, so the peaks are now valleys. The dilation with a horizontal line of 3 pixels fills the narrow valley at x = 2. The wide valley keeps the value 40 after the dilation, so reconstruction by erosion brings its rim back exactly. Its bottom of 10 is only one pixel wide, so it is filled to 40.

Complexity

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

N is the number of pixels per channel and K the size of the element. The reconstruction adds O(N).

Artifacts and limitations

Limitations

  • Dark objects joined to a large dark object by a thin bridge come back with it.

Artifacts

  • Thin dark bridges keep small dark objects alive.

Tests

The reference dilates with scipy.ndimage.grey_dilation on the extended plane and reconstructs with skimage.morphology.reconstruction. The cases cover all five border modes.

References