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.
How it works¶
- Erode the image with the structuring element.
- Reconstruct the erosion by dilation under the image.
Mathematical foundation¶
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¶
- Extend the image with the border mode and erode it with the element, then cut the extension off.
- 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¶
- Vincent, L. Morphological grayscale reconstruction in image analysis, applications and efficient algorithms. IEEE Transactions on Image Processing 2(2), 176 to 201, 1993. DOI 10.1109/83.217222.
- Soille, P. Morphological Image Analysis, 2nd edition. Springer, 2004. DOI 10.1007/978-3-662-05088-0.
- scikit-image documentation, skimage.morphology.reconstruction. https://scikit-image.org/docs/stable/api/skimage.morphology.html#skimage.morphology.reconstruction