Skip to content

Opening by reconstruction

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

Overview

Opening by reconstruction erodes the image, then reconstructs the erosion by dilation under the image. Bright objects the element does not fit into vanish, and every other bright object comes back with its exact shape. A plain opening would round their corners instead.

Three panels: noisy bright disks, the plain opening, which removes the white specks, and the opening by reconstruction, which also removes them and keeps the disks exactly. Three panels: noisy bright disks, the plain opening, which removes the white specks, and the opening by reconstruction, which also removes them and keeps the disks exactly.
Opening and opening by reconstruction with disk 2. Both remove the white specks, but only the reconstruction keeps the disks exactly as they were.

How it works

  1. Erode the image with the structuring element.
  2. Reconstruct the erosion by dilation under the image.

Mathematical foundation

\[ \gamma_R(f) = R^{\delta}_f(f \ominus B) \]

The formula shows the default parameter values.

where

  • \(B\): The structuring element
  • \(R^{\delta}_f\): Reconstruction by dilation under f

The erosion removes every bright object the element does not fit into. Reconstruction by dilation under the image then brings back every object that kept at least one pixel, with its exact shape. A plain opening would round the corners of those objects instead.

The erosion decides which bright objects are large enough: those that keep at least one pixel. Reconstruction then restores those objects completely, because growth under the image follows each object to its outline. The result is an opening, so it is idempotent and never brighter than the image, and it is a connected operator that never moves an edge.

Kernel or operator

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

Algorithm

  1. Extend the image with the border mode and erode it with the element, then cut the extension off.
  2. Reconstruct the erosion by dilation under 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 erosion, 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 10 10 40 10 10 90 120 90 10 10
Opening by reconstruction 10 10 10 10 10 90 90 90 10 10

The element is a horizontal line of 3 pixels. The erosion removes the peak of 40, one pixel wide. The wide peak keeps the value 90 after the erosion, so reconstruction brings its base back exactly. Its top of 120 is only one pixel wide, so it is cut to 90.

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

  • Objects joined to a large object by a thin bridge come back with it.

Artifacts

  • Thin bridges keep small objects alive.

Tests

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

References