Connected components

Closed Cédric Traizet requested to merge maskfiltering into develop


Implements new applications for large scale connected components segmentation.


The existing connected component application performs the following steps :

  1. Compute a label image (raster mono-band image with integer pixel values) from a multi-band image, a same label is assigned to "connected" pixels. Two pixels are said to be connected if the MuParser expression given as an input returns true (for example "distance<5"). The input image is therefore segmented in group of connected pixels. Additionally, a mask expression (also using MuParser) can be given to mask some pixels.

  2. The label image is converted to an ITK label map (see

  3. Geometric and radiometric attributes are computed using the label map and the input image (size, perimeter, mean, variance, kurtosis etc)

  4. An OBIA expression (MuParser) is used to filter some objects of the label map, for example filter objects that verify "size<15"

  5. The LabelMap is then vectorized.

  6. If connected component is used inside the large scale segmentation framework, some connected components that may have been splitted during vectorization will be merged.

There are two main problems with this application :

  • It does too many things, for example an user may want to only perform the vectorization of a label image (this is the original goal of the mask filtering application described at the beginning of this issue).

  • It doesn't work well with threading. Filtering (4) is done before fusion of segments (6), and the features are therefore computed on splitted segments.

We propose a different workflow for connected components, with the following steps :

  • Compute the label image (same as 1. )

  • Vectorize the label image, and merge the splitted segments

  • Compute the geometric features from the vector data (size and perimeter)

  • Filter the vector data using the computed geometric features and radiometric features.

Each of these steps is performed in a different application. This workflow does not use ITK's Label Maps, instead we use the persistent filters from the segmentation framework to perform vectorization (abstract filter PersistentImageToOGRLayerFilter), and the persistent filters from the sampling framework (abstract filter PersistentSamplingFilterBase).

Implementation Details

Classes and files
  • New persistent filter PersistentLabelImageVectorizationFilter and the associated decorator LabelImageVectorizationFilter in files otbPersistentLabelImageVectorizationFilter.h/hxx.

  • New filter ConnectedComponentStreamStitchingFilter in files otbConnectedComponentStreamStitchingFilter.h/hxx

  • New filter OGRDataToPolygonGeometricFeaturesFilter in files otbOGRDataToPolygonGeometricFeaturesFilter.h/hxx


There is one new application for each step described above :

  • ImageConnectedComponentSegmentation
  • LabelImageVectorization
  • ComputePolygonsGeometricFeatures
  • ObjectBasedFiltering.

There is also a composite application chaining all these applications : LargeScaleConnectedComponent.


validation tests have been created for the application


The copyright owner is CNES and has signed the ORFEO ToolBox Contributor License Agreement.

Edited by Cédric Traizet

Merge request reports