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

MedMLX

Synthetic FDG PET generated from CT and organ labels
Input Output
Aligned CT + organ labels + profiles Synthetic PET SUV volume

Use with MedMLX

The MedMLX MCP server is the lowest-friction way to use this model. It installs this runtime, and lets an AI agent describe, check and run fdg-pet-ct for you.

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.

Install

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

Run

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

from fdg_pet_ct_mlx.medmlx import run

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

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
labels_path MAISI label 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 never replaced

Arguments are keyword-only. Volumes are never registered or resampled. The profile JSON holds exactly two objects:

  • tissues, keyed by tissue name. Each has finite nonnegative suv_mean and suv_std, and a maisi_labels list of integer IDs in [0, 200], unique across tissues. unclassified_soft_tissue is required and covers unlisted labels.
  • scanner, with scatter_fraction and randoms_fraction in [0, 1], three finite nonnegative fwhm_mm values in array-axis order, and a finite positive counts_per_suv. Its product with count_level must be a positive normal float32.

The package ships no tissue statistics or scanner presets. The output is float32 SUV (body-weight convention, with no weight or dose normalization) on the CT shape and affine. run returns {"outputs": {"pet": path}, "details": {...}}, with the seed, count level, shape and profile path. 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, the CT factor exp(-0.02 * clip((HU + 1000) / 1000, 0, 3)) (a fixed heuristic, not measured attenuation), a scatter and randoms offset, a separable Gaussian blur (zero-padded, truncated at 3 sigma) and a Gaussian approximation to count noise. Its arrays must be 3D with matching shapes.
  • apply_lesion_uptake sets avid-label voxels to the host tissue mean times tumor_to_background, with optional multiplicative noise, a necrotic core at 0.2 times the host mean and Gaussian spill-over. Each avid label needs a host tissue. With no avid voxels it returns the activity unchanged, or raises if necrosis is requested.

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); apply_lesion_uptake draws only when heterogeneity > 0. The result is an MLX float32 SUV array on the input grid.

License

Apache-2.0. See third-party notices.

For research and education. Outputs require human review.

Metadata

Release files for fdg-pet-ct-mlx 0.2.6

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.2.6
File Size Uploaded Provenance Actions
fdg_pet_ct_mlx-0.2.6.tar.gz 21.2 kB Without provenance Details for fdg_pet_ct_mlx-0.2.6.tar.gz

Built distribution (wheel)

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

Total release size: 47.0 kB

Release files / fdg_pet_ct_mlx-0.2.6.tar.gz

Download URL fdg_pet_ct_mlx-0.2.6.tar.gz
Size 21.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1faa9fa57fb834a9ae8a274a65b3ee464a65c4bf90d050bdfa767390a636582d
BLAKE2b-256 checksum
How to use checksums
456c08f8f831409155b1786c3dd379b7c760ef51887c133bd5e3307d79540325
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","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.2.6-py3-none-any.whl

Download URL fdg_pet_ct_mlx-0.2.6-py3-none-any.whl
Size 25.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
20a48cbaf4541d14dd02586f72e1f01ed3dc066c651a65cb8ec84a8c1660aec2
BLAKE2b-256 checksum
How to use checksums
ad54efcef6b60425e024648b7a1b332612234a9c66d45323e7bc0c7be3afff82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","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.2.6

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