--- id: connected-components-3d version: "4.0.0" license: LGPL-3.0-or-later license_treatment: copyleft maintenance: active --- # 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). License: copyleft · Maintenance: active · Downloads: 220.0K/mo ## 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 above — 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 pip install connected-components-3d uv add connected-components-3d 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_current - Install friction: medium - Maintenance: active - Downloads: 220.0K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags connected components labeling 3d, multilabel image segmentation, volumetric connected components, 3d image processing, biomedical image analysis, instance segmentation labeling, connected components 2d 3d, image-processing, volumetric-segmentation, biomedical-imaging [View on SkillFed](https://skillfed.io/packages/connected-components-3d) · [View on PyPI](https://pypi.org/project/connected-components-3d/)