Skip to main content

Watertight, smooth STL reconstruction from NIfTI segmentations (boolean-CSG peel or independent organs).

Project description

NiftiMesh

Watertight, smooth STL reconstruction from NIfTI segmentations.

PyPI Python Downloads Release License: Apache 2.0

Turn a multi-label .nii.gz segmentation into one clean, closed STL surface per label — solid, watertight, manifold, self-intersection-free. In csg mode, adjacent regions share their interface seam bit-identically, so the parts assemble seamlessly in 3D Slicer / Mimics.

Left → right: naive marching cubes (voxel staircase) · a typical 3D Slicer default export · NiftiMesh (smooth, watertight, seamless).

What it's for

A multi-label segmentation volume → per-label STL meshes. Two modes:

  • csg — for one structure split by internal interfaces: lung lobes / segments, Couinaud liver segments. Neighbouring labels share their cut seam exactly (no crack, no black line).
  • independent — for disjoint organs (liver + spleen + kidneys, vessels): each label becomes its own closed, smoothed surface.

You define the output names — nothing is hard-coded to any anatomy.

Install

pip install "niftimesh[csg]"   # csg mode (needs meshlib)
pip install niftimesh          # independent + naive modes only

Python ≥ 3.9. NIfTI is read via nibabel (bundled) or SimpleITK if installed. Prebuilt wheels are also attached to each GitHub Release.

Usage

# names from a JSON file: {"1": "left_lower_lobe", "2": "left_upper_lobe", ...}
niftimesh seg.nii.gz out/ --mode csg --label-names names.json --suffix _3d

# omit --label-names to get label_1.stl, label_2.stl, ...
niftimesh organs.nii.gz out/ --mode independent
from niftimesh import nifti_to_stl

nifti_to_stl("seg.nii.gz", "out/", mode="csg",
             label_names={1: "left_lower_lobe", 2: "left_upper_lobe"})

# in-memory: numpy (z, y, x) label volume -> {label: vtkPolyData}
from niftimesh import reconstruct
meshes = reconstruct(seg, spacing=(0.84, 0.84, 1.0), mode="independent")

License

Apache 2.0 © 2026 Justin

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

niftimesh-0.1.1.tar.gz (3.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

niftimesh-0.1.1-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file niftimesh-0.1.1.tar.gz.

File metadata

  • Download URL: niftimesh-0.1.1.tar.gz
  • Upload date:
  • Size: 3.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for niftimesh-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3a33219cb422bb3618588d726fcb2b3ad8fd5055faac2c8373910a18d55d6508
MD5 cb68e7ecbef4d3ccff5202feaf8fef56
BLAKE2b-256 568c4791a1895a38db822975ae834b3d4d46b3a67424dddd935cc0a233de8eb2

See more details on using hashes here.

Provenance

The following attestation bundles were made for niftimesh-0.1.1.tar.gz:

Publisher: publish.yml on 77even/NiftiMesh

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file niftimesh-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: niftimesh-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for niftimesh-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eaec6a65582c38f1869e2e79fad72a430416be0e7a66dcca68a8e5ae8d67d95e
MD5 09edc1c0287e37bdfaff193593346434
BLAKE2b-256 f278235685e3eee7e29c64e5c1c5867e95c09e2eff302472d9ac8eff2ff3bbcc

See more details on using hashes here.

Provenance

The following attestation bundles were made for niftimesh-0.1.1-py3-none-any.whl:

Publisher: publish.yml on 77even/NiftiMesh

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page