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).
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-3duv
uv add connected-components-3dpoetry
poetry add connected-components-3dInstalling 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
Tags
More Scientific/Engineering packages
NumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
pandaspandas provides fast, flexible data structures…
permissive · top 100 on PyPI
scipyscipy provides numerical algorithms for…
permissive · top 100 on PyPI
scikit-learnscikit-learn provides a comprehensive Python…
permissive · top 1,000 on PyPI
dilldill extends Python's pickle module to…
permissive · top 1,000 on PyPI
multiprocessMultiprocess is an enhanced fork of Python's…
permissive · top 1,000 on PyPI
edtComputes Euclidean distance transforms for 1D,…
copyleft · top 15,000 on PyPI
fill-voidsFills interior voids in 2D and 3D binary images…
copyleft · top 15,000 on PyPI
nnunetv2nnU-Net is a semantic segmentation framework…
permissive · top 15,000 on PyPI
opensimplexGenerates OpenSimplex noise across 2D, 3D, and…
permissive · top 15,000 on PyPI
labelboxLabelbox is a Python SDK for interacting with…
permissive · top 15,000 on PyPI
label-studioLabel Studio is a web-based data annotation…
permissive · top 15,000 on PyPI
skanAnalyzes skeleton (thin object) images to…
permissive · top 15,000 on PyPI
face-alignmentDetects 2D and 3D facial landmarks from images…
permissive · top 15,000 on PyPI
batchgeneratorsbatchgenerators provides data augmentation…
permissive · top 15,000 on PyPI
cellposeCellpose segments cells and nuclei in…
permissive · top 15,000 on PyPI