Metadata-Version: 2.5
Name: lesiondiffusion-mlx
Version: 0.2.1
Summary: Native MLX implementation of LesionDiffusion
Author: Joseph Sandoval, Alfredo Sandoval Jr.
License-Expression: Apache-2.0 AND MIT 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.2
Requires-Dist: safetensors<1,>=0.6
Requires-Dist: scipy<2,>=1.15
Requires-Dist: tokenizers<1,>=0.21
Provides-Extra: conversion
Requires-Dist: torch<3,>=2.13; extra == 'conversion'
Provides-Extra: dev
Requires-Dist: einops<0.9,>=0.8.1; extra == 'dev'
Requires-Dist: hypothesis<7,>=6.100; extra == 'dev'
Requires-Dist: pillow<14,>=13; 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: scipy-stubs<1.19,>=1.18.1.1; extra == 'dev'
Requires-Dist: torch<2.14,>=2.13; extra == 'dev'
Provides-Extra: reference
Requires-Dist: einops==0.8.2; extra == 'reference'
Requires-Dist: omegaconf==2.3.1; extra == 'reference'
Requires-Dist: transformers==5.19.0; extra == 'reference'
Description-Content-Type: text/markdown

# lesiondiffusion-mlx

Add synthetic lesions to CT with native MLX, with controls for organ, size, placement and phenotype.

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

![Liver CT before and after lesion generation; the contour marks the generated lesion.](https://raw.githubusercontent.com/MedMLX/lesiondiffusion-mlx/main/docs/showcase.png)

*Liver CT before and after lesion generation; the contour marks the generated lesion.*

| Input | Output |
| :--- | :--- |
| CT + aligned binary organ mask | Synthetic CT and lesion mask |

**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/lesiondiffusion-mlx"
uv pip install \
  "lesiondiffusion-mlx[conversion] @ git+$repo" \
  huggingface-hub
```

Get `LMNet.ckpt`, `LINet.ckpt` and `VQ.ckpt` from the [upstream weights folder](https://drive.google.com/drive/folders/1n6_eAWhsHBFBYtDxPtp_FXp_tNHhOCHi). Convert once, then generate:

```python
from pathlib import Path

from huggingface_hub import hf_hub_download
from lesiondiffusion_mlx import write_conversion

tokenizer = hf_hub_download("microsoft/BiomedCLIP-PubMedBERT_256-vit_base_patch16_224", "tokenizer.json")
write_conversion(
    checkpoints={"lmnet": Path("LMNet.ckpt"), "linet": Path("LINet.ckpt"), "vq": Path("VQ.ckpt")},
    tokenizer_path=Path(tokenizer),
    output_dir=Path("lesiondiffusion-weights"),
)
```

```python
from lesiondiffusion_mlx.medmlx import run

result = run(
    image_path="ct_1mm_ras.nii.gz",
    organ_mask_path="liver_mask.nii.gz",
    weights_path="lesiondiffusion-weights",
    output_dir="out",
    organ="liver",
    lesion_type="tumor",
    bbox_size_mm=[30, 30, 20],
    placement="inside_parenchyma",
)
print(result["outputs"]["synthetic_image"])
```

Inputs must support the documented crop sizes. Outputs use a RAS 1 mm grid; voxels outside the lesion can change. Synthetic output is not ground truth.

## 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.
