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.
How it works¶
- Dilate the image with the structuring element.
- Reconstruct the dilation by erosion over the image.
Mathematical foundation¶
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¶
- Extend the image with the border mode and dilate it with the element, then cut the extension off.
- 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¶
- 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