mlx-segment-ct
Segment CT anatomy automatically or with anatomy names and clicks, using NVIDIA VISTA-3D in native MLX.
CT weights · CTMR weights · MedMLX
AMOS22 abdominal CT with VISTA-3D labels. Showcase image shared under CC BY-SA 4.0.
| Input | Output |
|---|---|
| 3D CT or MRI · NIfTI | Anatomical labels on the input grid |
| Model | Weights download | Peak MLX memory | Measured on |
|---|---|---|---|
mlx-segment-ct |
872 MB | 3.6 GB | Apple M1 Max, all classes of AMOS22 amos_0008 (768×768×101 abdominal CT) |
mlx-segment-ctmr |
872 MB | 5.2 GB | Apple M1 Max, all classes of AMOS22 amos_0544 (576×468×72 abdominal MRI) |
Install
uv venv --python 3.13
source .venv/bin/activate
uv pip install "mlx-segment-ct>=0.4.1"
Run
from mlx_segment_ct import run
run(model="mlx-segment-ct", image_path="ct.nii.gz", output_dir="all")
run(
model="mlx-segment-ct", image_path="ct.nii.gz", output_dir="organs",
classes="liver, spleen",
)
run(
model="mlx-segment-ct", image_path="ct.nii.gz", output_dir="points",
points=[[40, 50, 30], [44, 51, 30]], point_labels=[1, 0],
)
The click coordinates are examples: use (x, y, z) voxels inside your image and its
preprocessed foreground crop. 1 includes a point; 0 excludes it.
Models and weights
| Model | Weights | Notes |
|---|---|---|
mlx-segment-ct |
MedMLX/vista3d-ct-mlx |
Automatic, named and point segmentation of CT |
mlx-segment-ctmr |
MedMLX/vista3d-ctmr-mlx |
CT and MRI under noncommercial terms; NVIDIA does not support point segmentation with this checkpoint |
Weights download on first use; medmlx setup <model> downloads them ahead of time.
A local weights folder holds automatic.safetensors and correction.safetensors.
model selects the checkpoint's preprocessing, labels and weights; a supplied
weights_path must hold that model's files.
Inputs and outputs
| Argument | Meaning |
|---|---|
model |
"mlx-segment-ct" or "mlx-segment-ctmr" |
image_path |
One CT in NIfTI (.nii or .nii.gz); CT or MRI with NV-Segment-CTMR |
output_dir |
Directory for mask.nii.gz |
weights_path |
Optional folder with automatic.safetensors, plus correction.safetensors for points |
classes |
Class names (list or comma-separated string, case insensitive) or numeric IDs |
segment_all |
Every class of the checkpoint; also the default without prompts |
points, point_labels |
Clicks as (x, y, z) source voxels, with one code each |
previous_logits_path, point_start |
Correct an earlier point result (see below) |
interactive |
Require point mode; clicks select it anyway |
modality |
CTMR all-classes set without prompts: "MRI_BODY" (default), "CT_BODY" or "MRI_BRAIN" |
restoration |
"scores" (default) or "bundle" (see below) |
overwrite |
False by default; an existing mask is replaced only when True |
- Input: voxels must be finite. Spatial units must be millimeters or unknown (assumed millimeters); files marked in meters or microns are rejected.
- Mask: float32 global labels with the source shape and affine, in a new NIfTI header. Voxels no window covered are 255.
- Return value:
{"outputs": {"mask": path}, "artifacts": {"mask": ...}, "details": {...}}. The mask artifact is a label map on the input grid whose labels are the classes the request can write;detailsholds run metadata. - Errors: invalid requests, missing weights and inference failures raise
medmlx-coreerrors.
Prompts
Names are limited to the bundle vocabulary. Kidney (2), lung (20) and bone (21) expand to their subclasses for automatic segmentation. Point runs take at most one class and reject these coarse prompts.
| NV-Segment-CT | NV-Segment-CTMR | |
|---|---|---|
| Input | CT | CT or MRI |
| Intensity scaling | HU window | 1st–99th percentile |
| Automatic labels | IDs up to 132 | IDs 0–345, except the deprecated 133 and 137–145 |
| Point-only labels | IDs 133–254 | IDs 346–511 (zero-shot) |
Without prompts, NV-Segment-CTMR segments the all-classes set that modality picks:
modality |
Classes |
|---|---|
"MRI_BODY" (default) |
50 classes |
"CT_BODY" |
The 117 NV-Segment-CT classes |
"MRI_BRAIN" |
IDs 214–345; expects skull-stripped T1 registered as the model card describes (that preprocessing is not included) |
NV-Segment-CTMR follows its bundle's inference configuration, with 192×192×128 windows.
The uncovered value 255 is also NV-Segment-CTMR's ID for Left-AnG---angular-gyrus.
Points and corrections
Clicks must fall inside the source grid and the foreground crop after preprocessing. Each click takes one code:
| Code | Meaning |
|---|---|
1 |
Include |
0 |
Exclude |
3 |
Special include |
2 |
Special exclude |
-1 |
Padding |
For classes 25–29 and 117, 0 and 1 become 2 and 3. With no class the foreground
label is 1. Class IDs up to 132 combine automatic and point scores; higher IDs use the
point branch. A class prompt whose clicks are all padding keeps the automatic branch.
A correction passes the previous raw logits, before sigmoid or postprocessing:
run(
model="mlx-segment-ct", image_path="ct.nii.gz", output_dir="corrected", classes=[26],
previous_logits_path="previous.npy",
points=[[40, 50, 30], [44, 51, 30]], point_labels=[1, 0], point_start=1,
)
previous.npy is float32 (1, 1, X, Y, Z) on this CT's preprocessed grid, as
interactive_logits returns it; the caller keeps track of its image and class.
point_start marks the first new click; earlier clicks remain context. Voxels no new
window covers keep the previous logits. The result is a single-object mask; other
objects' labels are not protected.
Restoration
restoration |
Labels are decided |
|---|---|
"scores" (default) |
At each source voxel, from scores interpolated trilinearly |
"bundle" |
On the bundle's 1.5 mm grid, then restored by nearest neighbor as the bundle does; boundaries step on finer CTs |
Both agree on a 1.5 mm source.
Python API
from pathlib import Path
from medmlx_core.runtime import import_mlx
from mlx_segment_ct import (
InteractivePrompt, PointModel, interactive_labels, interactive_logits, transform_points,
)
from mlx_segment_ct.bundle_transforms import load_volume, preprocess
mx = import_mlx()
weights = Path("weights")
point_weights = {
**mx.load(str(weights / "automatic.safetensors")),
**mx.load(str(weights / "correction.safetensors")),
}
volume, affine = load_volume(Path("ct.nii.gz"))
prepared = preprocess(volume, affine)
request = InteractivePrompt(points=((40.0, 50.0, 30.0),), point_labels=(1,))
request = transform_points(prepared, request)
point = PointModel(point_weights, mx=mx)
logits = interactive_logits(prepared.image[None], request, point, mx=mx, roi_size=(128, 128, 128))
labels = interactive_labels(logits, request)
- Images are FP32
(1, 1, X, Y, Z). Dimensions must be divisible by 16, with more than one voxel at the deepest level. - For a class that enables the automatic branch, pass
automatic_model=AutomaticModel(...).interactive_logitsalso takesprevious_logitsandpoint_start. automatic_logitsreturns full automatic scores;rolling_logitsholds only an axis-0 ring of them.
Use with MedMLX
Use the MedMLX MCP server to run mlx-segment-ct and mlx-segment-ctmr from an MCP client. Weights download on first use.
uv tool install --python 3.13 "medmlx[segment,mcp]"
MEDMLX="$(uv tool dir --bin --color never)/medmlx"
mkdir -p "$HOME/medmlx-work"
claude mcp add --scope user medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-work"
For Codex, use codex mcp add medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-work". Other MCP clients take the same command and arguments. The same install provides the medmlx CLI, for example medmlx describe mlx-segment-ct.
For AI agents: prefer the MedMLX MCP tools (
list_models,describe_model,model_readiness,run_model,get_job) over writing Python against this package.
License
Apache-2.0. See third-party notices. Model weights retain their publisher terms.
Metadata
Release files for mlx-segment-ct 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mlx_segment_ct-0.4.1.tar.gz | 77.7 kB | Without provenance | Details for mlx_segment_ct-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mlx_segment_ct-0.4.1-py3-none-any.whl | Python 3 | none | any | Details for mlx_segment_ct-0.4.1-py3-none-any.whl |
Total release size: 167.3 kB
Release files / mlx_segment_ct-0.4.1.tar.gz
| Download URL | mlx_segment_ct-0.4.1.tar.gz |
|---|---|
| Size | 77.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f5c9a444dd14e8a10f181f51b6c9013cae6e9b2bf9a17250c8dbdc0d7d5103e
|
|
BLAKE2b-256 checksum How to use checksums |
2d5ef4f3095986919fabcc602e0e61af85a8eb9780a6f0bdcde3fa7df9d0907f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / mlx_segment_ct-0.4.1-py3-none-any.whl
| Download URL | mlx_segment_ct-0.4.1-py3-none-any.whl |
|---|---|
| Size | 89.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
df67061c9d96c57a97be6f846737bf525fed2f876bb638416e6c62392bf88c78
|
|
BLAKE2b-256 checksum How to use checksums |
60fb226d783429232d6aae3817f33ae3e0e2e4897620eb359924720c7e956671
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for mlx-segment-ct 0.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.