Skip to main content

fdg-pet-ct-mlx

Generate synthetic FDG PET activity from CT and organ labels with native MLX. Includes scanner blur, scatter and count noise.

PyPI Python License Apple Silicon MedMLX

Synthetic FDG PET generated from CT and organ labels
Input Output
Aligned CT + organ labels + profiles Synthetic PET SUV volume
Model Weights download Peak MLX memory Measured on
fdg-pet-ct None 2.7 GB 400×400×284 whole-body CT

Install

uv venv --python 3.13
source .venv/bin/activate
uv pip install "fdg-pet-ct-mlx>=0.5.1"

Run

With aligned CT and MAISI label volumes and your own profile JSON:

from fdg_pet_ct_mlx import run

result = run(
    image_path="ct.nii.gz",
    label_map_path="labels.nii.gz",
    profile_path="profiles.json",
    output_dir="outputs",
    seed=7,
)
print(result["outputs"]["image"])

run checks the image geometry and your profiles, then writes pet.nii.gz on the CT grid. No model weights are needed. Synthesis is in image space, without projection physics or reconstruction.

Inputs and outputs

Argument Meaning
image_path One finite scalar 3D CT in NIfTI, in HU, with spatial units in mm, m or micron (unset is mm)
label_map_path MAISI label map: IDs integers in [0, 200], with the CT's shape and affine (absolute tolerance 1e-5); spatial units mm or unset
profile_path Profile JSON, described below
output_dir Directory for pet.nii.gz
count_level Finite positive multiplier on counts_per_suv; default 1.0
seed Integer in [0, 4294967294]; activity uses seed, acquisition seed + 1
overwrite False by default; an existing pet.nii.gz is replaced only when True

Arguments are keyword-only. Volumes are never registered or resampled.

The profile JSON holds exactly two objects. The package ships no tissue statistics or scanner presets.

Object Field Requirement
tissues One entry per tissue name unclassified_soft_tissue is required and covers unlisted labels
suv_mean, suv_std Nonnegative and at most the float32 maximum (about 3.4e38)
maisi_labels Integer IDs in [0, 200], unique across tissues
scanner scatter_fraction, randoms_fraction In [0, 1]
fwhm_mm Three finite nonnegative values in array-axis order
counts_per_suv Finite and positive; its product with count_level must be a positive normal float32
  • Output: float32 SUV (body-weight convention, with no weight or dose normalization) on the CT grid, with the CT's header, so its spatial units are the CT's and its display range (cal_min, cal_max) is unset.
  • Return value: {"outputs": {"image": path}, "artifacts": {"image": ...}, "details": {...}}: the image artifact marks a synthetic SUV image on the CT grid, and details holds run metadata.
  • Errors: invalid inputs raise InvalidInputError.

Python API

from dataclasses import dataclass

import mlx.core as mx

from fdg_pet_ct_mlx.acquisition import apply_acquisition_model
from fdg_pet_ct_mlx.activity import synthesize_activity_map


@dataclass(frozen=True)
class Tissue:
    suv_mean: float
    suv_std: float
    maisi_labels: tuple[int, ...]


@dataclass(frozen=True)
class Organs:
    tissues: dict[str, Tissue]

    def lookup_table(self, size: int) -> tuple[float, ...]:
        table = [self.tissues["unclassified_soft_tissue"].suv_mean] * size
        for tissue in self.tissues.values():
            for label in tissue.maisi_labels:
                if label < size:
                    table[label] = tissue.suv_mean
        return tuple(table)


@dataclass(frozen=True)
class Scanner:
    scatter_fraction: float = 0.05
    randoms_fraction: float = 0.02
    fwhm_mm: tuple[float, float, float] = (5.0, 5.0, 5.0)
    counts_per_suv: float = 100.0


organs = Organs({
    "background": Tissue(0.0, 0.0, (0,)),
    "unclassified_soft_tissue": Tissue(1.0, 0.1, (1,)),
})
labels = mx.ones((16, 16, 16), dtype=mx.int32)
activity = synthesize_activity_map(labels, organs, seed=7, mx=mx)
pet = apply_acquisition_model(
    activity, mx.zeros(labels.shape, dtype=mx.float32), scanner=Scanner(),
    count_level=1.0, spacing_mm=(2.0, 2.0, 2.0), seed=8, mx=mx,
)
print(pet.shape, pet.dtype)  # (16, 16, 16), float32

These profile values are placeholders, not calibrated tissue statistics or a scanner preset. Any object with the attributes documented in fdg_pet_ct_mlx.profiles works.

  • synthesize_activity_map maps 3D integer or integral float MAISI labels in [0, 2³¹ − 1] to SUV. Boolean, complex and invalid label volumes raise ValueError.

  • apply_acquisition_model applies, in order:

    1. the CT factor exp(-0.02 * clip((HU + 1000) / 1000, 0, 3)), a fixed heuristic, not measured attenuation;
    2. a scatter and randoms offset;
    3. a separable Gaussian blur, zero-padded and truncated at 3 sigma;
    4. a Gaussian approximation to count noise.

    Its arrays must be 3D with matching shapes.

  • spacing_mm and fwhm_mm follow array-axis order, whatever the orientation. Matching shapes do not prove alignment; register the volumes first.

  • Each noisy step draws one MLX normal field from mx.random.key(seed). The result is an MLX float32 SUV array on the input grid.

Use with MedMLX

Use the MedMLX MCP server to run fdg-pet-ct from an MCP client.

uv tool install --python 3.13 "medmlx[generate,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 fdg-pet-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.

Metadata

Release files for fdg-pet-ct-mlx 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fdg-pet-ct-mlx 0.5.1
File Size Uploaded Provenance Actions
fdg_pet_ct_mlx-0.5.1.tar.gz 18.9 kB Without provenance Details for fdg_pet_ct_mlx-0.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fdg-pet-ct-mlx 0.5.1
File Interpreter ABI Platform Actions
fdg_pet_ct_mlx-0.5.1-py3-none-any.whl Python 3 none any Details for fdg_pet_ct_mlx-0.5.1-py3-none-any.whl

Total release size: 41.8 kB

Release files / fdg_pet_ct_mlx-0.5.1.tar.gz

Download URL fdg_pet_ct_mlx-0.5.1.tar.gz
Size 18.9 kB
Tags Source
SHA-256 checksum
How to use checksums
35f9cc60eeb11541da0e7697d730ac62f78b2036093855acee9c4d62f6182356
BLAKE2b-256 checksum
How to use checksums
e06c8a83ea909c18d8e8c57ffe9a260c84f0bdbfa5bccc25acdd20ce50c7761b
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 / fdg_pet_ct_mlx-0.5.1-py3-none-any.whl

Download URL fdg_pet_ct_mlx-0.5.1-py3-none-any.whl
Size 22.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f0f2379cf5a22554cd751679cb929ed8df862572d8b8180bc38b05c1c2d21b91
BLAKE2b-256 checksum
How to use checksums
6675b7980cc398ced811a879492d663dcd8024864820d88e4e60370c3a44944e
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 fdg-pet-ct-mlx 0.5.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page