skillfed

connected-components-3d

Connected components on discrete and continuous multilabel 3D and 2D images. Handles 26, 18, and 6 connected variants; periodic boundaries (4, 8, & 6).

connected-components-3d v4.0.0 220.0K downloads/30d#9,317 on PyPI457
Copyleft license LGPL-3.0-or-later Active released

What it is and what it does

connected-components-3d is a fast connected-components labeling library for 2D and 3D images that handles multilabel, binary, and continuous-valued data in a single pass. Unlike typical implementations that require masking and relabeling each label separately, this package labels all connected components simultaneously, making it particularly suited for densely labeled biomedical images where hundreds to thousands of labels may be present. It uses a 3D variant of the two-pass Rosenfeld-Pflatz method augmented with Union-Find and decision trees, supporting 26, 18, or 6-connected neighborhoods in 3D and 4 or 8-connected in 2D.

The package depends only on numpy and provides functions for component extraction, centroid and bounding-box calculation, small-object removal, contact-surface-area computation, and per-voxel connectivity graphs. It handles edge cases like periodic boundaries, memory-mapped files for images larger than RAM, and compressed output formats. The implementation supports Python 3.9 through 3.14 and is actively maintained.

Use it for:

  • Segment densely labeled 3D biomedical images where each voxel may belong to a different instance or semantic label.
  • Extract and analyze individual connected components from instance segmentation outputs without repeated masking and relabeling.
  • Process continuous-valued grayscale images by grouping nearby voxel values into components using a delta threshold.
  • Handle very large volumetric datasets that exceed available RAM using memory-mapped files or stack-based compressed output.
  • Compute component statistics (centroids, bounding boxes, voxel counts, contact networks) in a single operation after labeling.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Labels connected components in 2D and 3D images with support for multilabel, continuous-valued, and binary data using 26, 18, or 6-connected neighborhoods in 3D or 4 and 8-connected in 2D.

Yes, if you work with 2D/3D image segmentation or multilabel volumetric data. The single-pass multilabel algorithm offers genuine performance and convenience advantages over masking-based approaches. The copyleft license (LGPL-3.0-or-later) requires careful review if you plan proprietary distribution. Install friction is moderate due to C++ compilation, but prebuilt wheels cover most platforms. No known security vulnerabilities.

Install

connected-components-3d on PyPI

pip

pip install connected-components-3d

uv

uv add connected-components-3d

poetry

poetry add connected-components-3d

Installing connected-components-3d

Before you install

Medium install friction due to compiled C++ extension, but prebuilt wheels are available for Python 3.10–3.13 across macOS, Windows, and Linux. Requires numpy. Occasional binary incompatibility with numpy can force source compilation, which requires a C++ compiler.

License in practice

Licensed under LGPL-3.0-or-later (copyleft). Derivative works and modifications must be released under compatible terms; proprietary use requires careful licensing review or source code disclosure.

Quickstart

pip install connected-components-3d

import connected_components_3d
import numpy as np

labels_in = np.ones((512, 512, 512), dtype=np.int32)
labels_out = connected_components_3d.connected_components(labels_in)

Requires C++ compiler if prebuilt wheels unavailable for your platform; occasional numpy binary incompatibility may require source compilation or numpy upgrade.

Verify before relying

  • Performance improvement magnitude over scipy on multilabel images (description claims 'one or more orders of magnitude' but provides no quantified benchmark data).
  • Memory efficiency gains for very large volumes (description mentions memmap and stack processing but no concrete memory savings are documented).
  • Whether binary image optimizations mentioned as 'not implemented yet' have been added in version 4.0.0.

Package facts

License LGPL-3.0-or-later (copyleft)
Python support supports the current Python release (<4.0,>=3.9)
Install friction medium — platform-specific wheel
Runtime dependencies 1 — numpy
Maintenance actively maintained — 70 days since the last release
Last repo commit
First released
Downloads 219,951/month — #9,317 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: connected_components_3d-4.0.0-cp310-cp310-macosx_10_9_x86_64.whl; connected_components_3d-4.0.0-cp310-cp310-macosx_11_0_arm64.whl; connected_components_3d-4.0.0-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; connected_components_3d-4.0.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; connected_components_3d-4.0.0-cp310-cp310-win32.whl; connected_components_3d-4.0.0-cp310-cp310-win_amd64.whl; connected_components_3d-4.0.0-cp311-cp311-macosx_10_9_x86_64.whl; connected_components_3d-4.0.0-cp311-cp311-macosx_11_0_arm64.whl; connected_components_3d-4.0.0-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; connected_components_3d-4.0.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; connected_components_3d-4.0.0-cp311-cp311-win32.whl; connected_components_3d-4.0.0-cp311-cp311-win_amd64.whl; connected_components_3d-4.0.0-cp312-cp312-macosx_10_13_x86_64.whl; connected_components_3d-4.0.0-cp312-cp312-macosx_11_0_arm64.whl; connected_components_3d-4.0.0-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; connected_components_3d-4.0.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; connected_components_3d-4.0.0-cp312-cp312-win32.whl; connected_components_3d-4.0.0-cp312-cp312-win_amd64.whl; connected_components_3d-4.0.0-cp313-cp313-macosx_10_13_x86_64.whl; connected_components_3d-4.0.0-cp313-cp313-macosx_11_0_arm64.whl

Keywords: connected-components, CCL, volumetric-data, numpy, connectomics, image-processing, biomedical-image-processing, decision-tree, union-find, sauf, 2d, 3d

Development Status :: 5 - Production/StableIntended Audience :: DevelopersIntended Audience :: Science/ResearchOperating System :: MacOSOperating System :: Microsoft :: Windows :: Windows 10Operating System :: POSIXProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Scientific/Engineering

Tags

connected components labeling 3dmultilabel image segmentationvolumetric connected components3d image processingbiomedical image analysisinstance segmentation labelingconnected components 2d 3d
image-processingvolumetric-segmentationbiomedical-imaging

More Scientific/Engineering packages