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.4.0"

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",
    mask_path="labels.nii.gz",
    profile_path="profiles.json",
    output_dir="outputs",
    seed=7,
)
print(result["outputs"]["image"])

The runner validates the image geometry and caller-supplied profiles, then writes pet.nii.gz on the CT grid.

No model weights are needed. This is image-space synthesis; it does not simulate 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
mask_path MAISI label map: IDs integers in [0, 200], with the CT's shape, affine (absolute tolerance 1e-5) and units
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 Finite and nonnegative
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 shape and affine.
  • 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 synthetic, not calibrated tissue statistics or a scanner preset. Profiles are duck-typed; fdg_pet_ct_mlx.profiles documents the attributes.

  • 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; the caller owns registration.

  • 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.4.0

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.4.0
File Size Uploaded Provenance Actions
fdg_pet_ct_mlx-0.4.0.tar.gz 19.2 kB Without provenance Details for fdg_pet_ct_mlx-0.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 42.8 kB

Release files / fdg_pet_ct_mlx-0.4.0.tar.gz

Download URL fdg_pet_ct_mlx-0.4.0.tar.gz
Size 19.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0cd838cd74a69b2c3df12ba4ad65779240ac7b0414e1d3faaf7481425d0ff1aa
BLAKE2b-256 checksum
How to use checksums
d826611e2daef6a223552f37839c91a279fe4a8b7b4163f21f30a39a8e25a774
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.4.0-py3-none-any.whl

Download URL fdg_pet_ct_mlx-0.4.0-py3-none-any.whl
Size 23.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e2286535932090f088dd7a4bf63505de3499c6a4ba4c063db12f70fc5f0a218
BLAKE2b-256 checksum
How to use checksums
8ff71dacf86575f4927a7b68632e5adef0daae8c79a13a7962fb91c29b6c8a5d
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.4.0

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