extract-connected-components <input> <output> [options]


Extracts connected components from input segmentation label image. By default, the largest connected component is extracted. In case of extract-connected-components -output-component-labels, the labels of the components are written instead.



Input segmentation image.


Extracted components or components label image.

Command options

-m <m>

Zero-based index of first connected component to extract. (default: 0)

-n <n>

Extract (at most) n components. (default: 1)


Extract all components.

-min-size <n>

Minimum number of component voxels. (default: 0)

-max-size <n>

Maximum number of component voxels. (default: all voxels)

-connectivity <num>

Type of voxel connectivity (4, 6, 18, or 26). (default: 26)

-ordering (none|largest|smallest)

Ordering of connected component labels based on component size:

  • none: Label components in no specific order.
  • largest: Label largest component first. (default)
  • smallest: Label smallest component first.

Write component labels instead of input labels.


Write binary mask with non-zero value at extracted components.

Standard options

-v, -verbose [n]

Increase/Set verbosity of output messages. (default: 0)

-debug [level]

Increase/Set debug level for output of intermediate results. (default: 0)

-version [major.minor]

Print version and exit or set version to emulate.


Print revision (or version) number only and exit.

-h, -help

Print help and exit.