Skip to content

Area closing

Fact Value
Also called Area closing filter, Grayscale area closing
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_closing_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 closing fills dark pits smaller than a given area, whatever their shape, after Vincent. It is the dual of the area opening: it treats dark spots as the area opening treats bright ones. Thin dark lines stay when their area is large, and nothing else changes. The filter runs in the PixelNexus engine, with scikit-image.

Four panels. A gray ground with a light disk, a thin horizontal line, a thin vertical line, small bright specks and small dark pits. With an area of 16, 64 and 256, the dark pits are gone, while every bright speck, the lines and the disk stay. Four panels. A gray ground with a light disk, a thin horizontal line, a thin vertical line, small bright specks and small dark pits. With an area of 16, 64 and 256, the dark pits are gone, while every bright speck, the lines and the disk stay.
Bright specks, two thin lines, dark pits of 9 pixels and a disk on a gray ground. Then the area closing with an area of 16, 64 and 256.

How it works

  1. Build the tree of the dark components of all threshold levels.
  2. Mark the components with fewer pixels than the area.
  3. Give each pixel the level of the nearest component that is kept.

Mathematical foundation

\[ \phi_a(I) = \bigwedge \{ \phi_B(I) : B \text{ connected},\ \lvert B \rvert \ge a \} \]

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 dark pixels split into connected components. The area closing removes every component with fewer than a pixels, so a pixel rises to the lowest level at which it still belongs to a large enough component. Vincent showed this equals the infimum of all closings 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, of the inverted image.

An area closing is an area opening of the inverted image, inverted back. So a dark component with fewer pixels than the area rises to the level of its surroundings.

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 Dark 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_closing_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_closing, which works on the max-tree of the inverted image.

Worked example

Area Specks left (1 / 2 / 3 / 4 px) Dark pits left Line kept
4 10 / 10 / 10 / 10 22 yes
16 10 / 10 / 10 / 10 0 yes
64 10 / 10 / 10 / 10 0 yes
256 10 / 10 / 10 / 10 0 yes

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.

The 22 dark pits have 9 pixels each, so an area of 4 keeps them and 16 fills all of them. The bright specks, the lines and the disk never change, since a closing only fills dark 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 pits were filled.

Tests

The result must equal scikit-image's own call with 4 neighbors, and a dark bar of 20 pixels must be filled at an area of 30. 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_closing.