Metadata-Version: 2.5
Name: mlx-segment-ct
Version: 0.2.1
Summary: Native MLX implementation of NV-Segment-CT (VISTA-3D)
Author: Joseph Sandoval, Alfredo Sandoval Jr.
License-Expression: Apache-2.0 AND BSD-3-Clause
License-File: LICENSE
License-File: THIRD_PARTY_NOTICES.md
Classifier: Operating System :: MacOS :: MacOS X
Requires-Python: <3.15,>=3.13
Requires-Dist: medmlx-core==0.2.3
Requires-Dist: nibabel<6,>=5.3
Requires-Dist: numpy<3,>=2.0
Requires-Dist: scipy<2,>=1.14
Provides-Extra: conversion
Requires-Dist: torch<3,>=2.13; extra == 'conversion'
Provides-Extra: dev
Requires-Dist: einops<1,>=0.8; extra == 'dev'
Requires-Dist: hypothesis<7,>=6.140; extra == 'dev'
Requires-Dist: monai==1.6.1; extra == 'dev'
Requires-Dist: pyright==1.1.414; extra == 'dev'
Requires-Dist: pytest<10,>=8.4; extra == 'dev'
Requires-Dist: ruff<1,>=0.13; extra == 'dev'
Requires-Dist: scikit-image<1,>=0.25; extra == 'dev'
Requires-Dist: scipy-stubs==1.18.1.1; extra == 'dev'
Requires-Dist: torch<3,>=2.13; extra == 'dev'
Description-Content-Type: text/markdown

# mlx-segment-ct

Segment CT anatomy automatically or with anatomy names and clicks, using NVIDIA VISTA-3D in native MLX.

[Docs](docs/technical.md) · [MedMLX](https://github.com/MedMLX)

![Automatic CT segmentation with selected organs and pelvic bones in 3D.](https://raw.githubusercontent.com/MedMLX/mlx-segment-ct/main/docs/showcase.png)

*Automatic CT segmentation with selected organs and pelvic bones in 3D.*

| Input | Output |
| :--- | :--- |
| 3D CT · NIfTI | Anatomical labels on the input grid |

**Apple Silicon · Metal · Python 3.13 / 3.14** · [uv](https://docs.astral.sh/uv/)

## Quick start

```bash
uv venv --python 3.13
source .venv/bin/activate
repo="https://github.com/MedMLX/mlx-segment-ct"
uv pip install \
  "mlx-segment-ct[conversion] @ git+$repo" \
  huggingface-hub
```

Download and convert the checkpoint once, then run:

```python
from pathlib import Path

from huggingface_hub import hf_hub_download
from medmlx_core.runtime import import_mlx
from mlx_segment_ct import mlx_correction_weights, mlx_weights

mx = import_mlx()
checkpoint = Path(hf_hub_download("nvidia/NV-Segment-CT", "vista3d_pretrained_model/model.pt"))
out = Path("weights")
out.mkdir(exist_ok=True)
mx.save_safetensors(
    str(out / "automatic.safetensors"), mlx_weights.convert_weights(checkpoint, mx=mx)
)
mx.save_safetensors(
    str(out / "correction.safetensors"),
    {k: mx.array(v) for k, v in mlx_correction_weights.convert_weights(checkpoint).items()},
)
```

```python
from mlx_segment_ct.medmlx import run

common = dict(image_path="ct.nii.gz", weights_path="weights")

run(**common, output_dir="all")  # all 117 classes
run(**common, output_dir="organs", prompt="liver, spleen")
run(
    **common,
    output_dir="points",  # clicks: (x, y, z) voxels
    points=[[40, 50, 30], [44, 51, 30]],
    point_labels=[1, 0],
)
```

Docs cover click prompts, interactive correction and the NV-Segment-CTMR checkpoint for CT and MRI.

## License

[Apache-2.0](LICENSE). See [third-party notices](THIRD_PARTY_NOTICES.md). Model weights retain their publisher terms.

For research and education. Outputs require human review.
