Area opening¶
| Fact | Value |
|---|---|
| Also called | Area opening filter, Grayscale area opening |
| Status | Implemented and tested |
| Family | Morphological filters |
| Engine | Science engine |
| Type | Nonlinear, morphological, connected attribute filter |
| Output | Image |
| Operator shown as | algorithm (exact) |
| Support radius | global |
| Code | engine/src/pixelnexus_engine/filters/tree_morphology.py, area_opening_filter |
| Operator code | engine/src/pixelnexus_engine/filters/tree_morphology.py, attribute_stages |
| Packages | scikit-image |
| Channels | RGB, Brightness only, Color only |
Overview¶
An area opening removes bright spots smaller than a given area, whatever their shape, after Vincent. Unlike an opening with a structuring element, it keeps thin long structures when their area is large enough, and it never changes the shape of what it keeps. The filter runs in the PixelNexus engine, with scikit-image.
How it works¶
- Build the tree of the bright components of all threshold levels.
- Mark the components with fewer pixels than the area.
- Give each pixel the level of the nearest component that is kept.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(a\): The area
- \(B\): A connected structuring element
Threshold the image at every level. At each level, the bright pixels split into connected components. The area opening removes every component with fewer than a pixels, so a pixel drops to the highest level at which it still belongs to a large enough component. Vincent showed this equals the supremum of all openings with connected structuring elements of at least a pixels. So no fixed shape is imposed, and what is kept is kept exactly. scikit-image computes it on a max-tree, after Salembier, Oliveras and Garrido.
An opening with a disk removes everything the disk does not fit in, so it also removes thin lines and rounds corners. The area opening asks only how many pixels a component has. Vincent showed that it is the largest of all openings with connected elements of the given area, so it removes as little as an opening can.
Kernel or operator¶
There is no fixed kernel. The Inspector asks the engine for the stages with the current settings.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Area area |
64 | 1 to 100000 px | Bright components with fewer pixels than this are removed. scikit-image uses 64. |
Neighbors connectivity |
8 (sides and corners) | 8 (sides and corners), 4 (sides only) | Which neighbors join a component. scikit-image uses 4, its connectivity 1. 8 is our choice, as for connected-component labeling. |
Channels channelScope |
RGB | RGB, Brightness only, Color only | Which part of the color image the filter changes. |
Implementation¶
area_opening_filter in engine/src/pixelnexus_engine/filters/tree_morphology.py rounds each plane of the channel scope to 8 bits and calls skimage.morphology.area_opening. The library builds a max-tree of the image, after Salembier, Oliveras and Garrido, and removes each node with fewer pixels than the area.
Worked example¶
| Area | Specks left (1 / 2 / 3 / 4 px) | Dark pits left | Line kept |
|---|---|---|---|
| 4 | 0 / 10 / 10 / 10 | 22 | yes |
| 16 | 0 / 0 / 0 / 10 | 22 | yes |
| 64 | 0 / 0 / 0 / 0 | 22 | yes |
| 256 | 0 / 0 / 0 / 0 | 22 | no |
The image of the figure, with 8 neighbors. There are 10 bright specks of each side from 1 to 4 pixels, so of 1, 4, 9 and 16 pixels. A speck is left when its corner pixel stays above 150. The dark pits are 3 x 3, and are counted by their pixels at or below 30. The line kept column says whether the horizontal line, 1 pixel thick and 70 long, stays above 150 along its whole length.
A speck is removed when it has fewer pixels than the area, so an area of 4 keeps the 2 x 2 specks, of exactly 4 pixels. At 64, every speck is gone, while the horizontal line of 70 pixels stays whole. At 256, the line goes too. The dark pits never change: an opening only removes bright structures.
Complexity¶
- Time: \(O(N log N)\)
- Memory: \(O(N)\)
N is the number of pixels, for building the tree.
Artifacts and limitations¶
Limitations
- Only size counts, so a small but important feature goes.
- Noise can join a small spot to a large region, which then survives.
Artifacts
- Flat plateaus where peaks were cut.
Tests¶
The result must equal scikit-image's own call. Small bright specks and a single pixel must go, while a thin line and a large rectangle stay exactly. The representation must have its three stages.
References¶
- Vincent, L. Morphological area openings and closings for grey-scale images. In Shape in Picture, Springer, 197 to 208, 1994. DOI 10.1007/978-3-662-03039-4_13.
- Salembier, P., Oliveras, A., and Garrido, L. Antiextensive connected operators for image and sequence processing. IEEE Transactions on Image Processing 7(4), 555 to 570, 1998. DOI 10.1109/83.663500.
- scikit-image documentation, skimage.morphology.area_opening.