
## LION (Lesion segmentatION): Loud. Proud. Unbounded. π¦
[](https://pepy.tech/projects/lionz)
[](https://zenodo.org/badge/latestdoi/685935027)<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[](https://www.gnu.org/licenses/gpl-3.0)
[](mailto:lalith@zenta.solutions)
LION has roared onto the scene, revolutionizing the way we view lesion segmentation. Born from the same lineage as lion 3.0, LION is laser-focused on tumor segmentation. Our curated models, each crafted with precision, cater to various tracers, setting the gold standard in lesion detection.
β¨ **Exclusive Engineering Paradigm**: With LION, segmentation is not just a task; it's an orchestrated dance of models. Define workflows for each model, mix and match channels as some models thrive on PET/CT while others are optimized for just PET or CT. Run them in a sequence that maximizes output and efficiency. This unique trait of LION lets you tailor the process to your exact needs, making lesion segmentation an art of precision.
π **Flexibility Unleashed**: Whether you're looking for a command-line tool for batch processing or a library package for your Python projects, LION has you covered. Seamlessly integrate it into your work environment and watch it shine.
Dive into the exciting world of PET tumor segmentation with LION and experience the future today!
π **Important Notification:** As of now, the LION tool is optimized and validated for FDG imaging. Development for PSMA imaging is ongoing and will be available soon. We appreciate your patience and understanding. Stay tuned for updates! π
---
## **Requirements** β
For an optimal experience with LION, ensure the following:
- **Operating System**: LION runs smoothly on Windows, Mac, or Linux.
- **Memory**: At least 32GB of RAM ensures LION operates without a hitch.
- **GPU**: For blazing-fast results, an NVIDIA GPU or an Apple MPS chip is highly recommended. But if you don't have one, fret not! LION will still get the job done, just at a more leisurely pace.
- **Python**: Version 3.10!
---
## **Installation Guide** π οΈ
Navigating the installation process is a breeze. Just follow the steps below:
**For Linux and MacOS** π§π
1. Create a Python environment, for example, 'lion-env'.
```bash
python3.10 -m venv lion-env
```
2. Activate your environment.
```bash
source lion-env/bin/activate # for Linux
source lion-env/bin/activate # for MacOS
```
3. Install LION.
```bash
pip install lionz
```
**From source using uv** π§βπ»
If you are working from a clone of this repository, the project is now managed with [uv](https://github.com/astral-sh/uv).
```bash
# inside the cloned repository
uv sync
uv run lionz -h
```
The `uv sync` command creates a virtual environment, resolves dependencies using `pyproject.toml`, and produces a `uv.lock` so builds stay reproducible.
## For Macs powered by Apple Silicon (M series chips with MPS) π
> Yes, it works. But you'll need to follow these steps carefully. Grab a β or πΊ β this may take a few minutes.
> Note: Please make sure you have the right version of `cmake`, as well as `ninja` installed.
> Also you need `git`, `xcode command line tools` installed. Using `brew` is the safest option.
1. Create and activate a virtual environment (We recommend Python 3.10 for stability)
```bash
python3.10 -m venv lion-env
source lion-env/bin/activate
```
2. Install lion and the MPS-compatible PyTorch fork
Youβll need a special PyTorch build tailored for Appleβs Metal backend (MPS), which doesnβt use CUDA.
```bash
pip install lionz
pip uninstall torch # ensures clean install; avoids conflicts with lion-installed version
git clone https://github.com/LalithShiyam/pytorch-mps.git
cd pytorch-mps
```
4. Fix your CMake version (IMPORTANT β οΈ)
**Do not use CMake 4.x** β it will break the build due to compatibility issues with `protobuf`.
Check your version:
```bash
cmake --version
```
If it's **4.0 or higher**, downgrade to a compatible version (e.g., 3.29.2):
```bash
pip uninstall cmake -y
pip install cmake==3.29.2
```
4. Build the custom PyTorch fork for MPS
This will build PyTorch without CUDA (which Apple Silicon doesnβt support anyway):
```bash
USE_CUDA=0 python setup.py develop --verbose 2>&1 | tee build.log
```
> β
This may take some time. If it completes without errors, youβre good to go.
5. Patch `nnUNetTrainer.py` (one-time fix)
Due to differences in PyTorch exports, `nnUNet` may crash with:
```
ImportError: cannot import name 'GradScaler' from 'torch'
```
To fix it:
1. Open the following file inside your lion-env folder:
```
~/lion-env/lib/python3.10/site-packages/nnunetv2/training/nnUNetTrainer/nnUNetTrainer.py
```
2. Replace this line 43:
```python
from torch import GradScaler
```
with:
```python
from torch.cuda.amp import GradScaler
```
β
Thatβs it!
Now youβre ready to use **LION on Apple Silicon** with MPS acceleration. πβ‘
If anything crashes, blame the silicon gods⦠or just open an issue. We're here to help.
**For Windows** πͺ
1. Set up a Python environment, say 'lion-env'.
```bash
python -m venv lion-env
```
2. Get your environment up and running.
```bash
.\lion-env\Scripts\activate
```
3. Hop over to the PyTorch website and fetch the right version for your system. This step is crucial!
4. Finish up by installing LION.
```bash
pip install lionz
```
---
## 𧬠Supported Models by Tracer Type
| Tracer | Model Name | Status | Training Dataset Size | Cancer Type |
|:------:|:----------:|:---------------------:|:------------------------------:|:------------------------------------------:|
| FDG | `fdg` | β
Stable & validated | 5,341 patients (multicenter) | `breast` `melanoma` `lung` `lymphoma` `colorectal` |
| PSMA | `psma` | π§ In development | ~1,200 patients (in progress) | `prostate` |
---
## **Usage Guide** π
**Command-line Tool for Batch Processing** π»
Starting with LION is as intuitive as it gets. Here's how:
```bash
lionz -d <path_to_image_dir> -m <model_name>
```
Replace `<path_to_image_dir>` with your image directory and `<model_name>` with your chosen segmentation model's name.
**Real-Life Usage Example π**
To run LION using the 'fdg' model on a batch of images located in `/path/to/dummy/image/directory`, you'd simply execute:
```bash
lionz -d /path/to/dummy/image/directory -m fdg
```
**Thresholding Feature βοΈ**
LION is also equipped with a thresholding feature to refine your segmentations. Just add -t and the value you want to use for thresholding.
**Important:** Thresholding is only supported with DICOM or SUV NIfTI inputs! If you don't require thresholding, feel free to use any LION-compliant input.
Here's how you can apply thresholding for SUV 2.5:
```bash
lionz -d /path/to/dummy/image/directory -m fdg -t 2.5
```
**Generating a MIP with overalayed segmentation**
If you want to have a quick glance at the segmentation by having a rotation MIP with the obtained segmentations overlayed all you need is to add the -gen-mip flag to your command.
```bash
lionz -d /path/to/dummy/image/directory -m fdg -gen-mip
```
And, if you ever find yourself needing some guidance:
```bash
lionz -h
```
This trusty command will spill all the beans about available models and their specialties.
### Using LION as a Library π¦π
LION isn't just a command-line powerhouse; itβs also a flexible library for Python projects. Hereβs how to make the most of it:
First, import the `lion` function from the `lionz` package in your Python script:
```python
from lionz import lion
```
#### *Calling the `lion` Function* π¦
The `lion` function is versatile and accepts various input types. It takes five main arguments:
1. `input`: The data to process, which can be:
- A path to an input file or directory (NIfTI, either `.nii` or `.nii.gz`).
- A tuple containing a NumPy array and its spacing (e.g., `numpy_array`, `(spacing_x, spacing_y, spacing_z)`).
- A `SimpleITK` image object.
2. `model_name`: The model name to use for segmentation.
3. `output_dir`: The directory where the results will be saved.
4. `accelerator`: The type of accelerator to use (`"cpu"`, `"cuda"`, or `"mps"` for Mac).
5. `threshold`: The value to use for thresholding. Optional
#### Examples πβοΈπ»
Here are some examples to illustrate different ways to use the `lion` function:
1. **Using a file path and multiple models:**
```python
lion('/path/to/input/file', 'fdg', '/path/to/save/output', 'cuda', 2.5)
```
2. **Using a NumPy array with spacing:**
```python
lion((numpy_array, (1.5, 1.5, 1.5)), 'psma', '/path/to/save/output', 'cuda', 2.5)
```
3. **Using a SimpleITK image:**
```python
lion(simple_itk_image, 'fdg', '/path/to/save/output', 'cuda', 2.5)
```
#### Usage of `lion()` in your code
To use the `lion()` function, ensure that you wrap the function call within a main guard to prevent recursive process creation errors:
```python
from lionz import lion
if __name__ == '__main__':
input_file = '/path/to/input/file'
model = 'fdg'
output_directory = '/path/to/save/output'
accelerator = 'cuda'
threshold = 2.5
lion(input_file, models, output_directory, accelerator, threshold)
```
---
## **Directory Conventions for LION** ππ·οΈ
For batch mode users β οΈ, ensure your data structure and naming conventions align with the provided guidelines. LION is compatible with both DICOM and NIFTI formats. For DICOM, LION discerns the modality from tags. For NIFTI, file naming is key. Allowed modality tags: `PT` for PET, `CT` for CT as of now.
**Directory Structure** π³
Organize your dataset as follows:
```
π LION_data/
β
βββ π Subject1
β βββ π Modality1
β β βββ π File1.dcm
β βββ π Modality2
β βββ π File2.dcm
βββ π Subject2
β βββ π Modality1_Subject2.nii
β βββ π Modality2_Subject2.nii
βββ π Subject3
βββ π Modality1_Subject3.nii
βββ π Modality2_Subject3.nii
```
## **Naming Conventions for NIFTI** π
Ensure you attach the correct modality as a prefix in the file name.
---
### Dataset Organization for FDG Model
For the FDG model, your dataset must be organized strictly according to the guidelines below, considering PT (Positron Emission Tomography) and CT (Computed Tomography) as the primary modalities:
```
π FDG_data/
β
βββ π Patient1
β βββ π AnyFolderNameForPT
β βββ π DICOM_File1.dcm
β βββ π DICOM_File2.dcm
β βββ ...
βββ π Patient2
β βββ π PT_Patient2.nii
βββ π Patient3
βββ π PT_Patient3.nii.gz
```
**Important Guidelines:**
- Each patient's data must be stored in a dedicated folder.
- For DICOM format:
- Patient1's example demonstrates the DICOM structure. Inside each patient's main folder, the inner folders can have any name for PT modality. Multiple DICOM files can be stored in these folders. The modality (PT) will be inferred from the DICOM's modality tag.
- For NIFTI format:
- Patient2 and Patient3 examples demonstrate the NIFTI structure. For these, PT modality is directly within the patient's folder with the `.nii` extension. Adjust the naming structure as per the specifics of your dataset if required.
- Only DICOM and NIFTI formats are supported. No other imaging formats are allowed.
- Adhering to these guidelines is non-negotiable for both FDG and PSMA models.
---
# π LIONz Output Folder Structure for FDG Model
When you run the FDG model, an output folder named `lionz-fdg-<timestamp>` will be generated in the respective subject directory. Here's a breakdown of the folder structure:
```
π lionz-fdg-2023-09-18-10-07-25/
β
β
βββ π PT
β βββ π PT_0147.nii.gz
β
βββ π segmentations
β βββ π 0147_no_tumor_seg.nii.gz
β βββ π½ 0147_rotational_mip.gif (optional)
β
βββ π stats
βββ π 0147_metrics.csv
```
## π Breakdown:
- π **segmentations**: Houses all segmentation-related files.
- π NIFTI files showing segmentations.
- π½ GIF files representing various views. Only when requested by the user.
- π **stats**: Contains `.csv` files with metrics related to the analysis.
---
Harness the power of LION and elevate your PET tumor segmentation game! ππ¦
Remember, the LION team is here to support you every step of the way. Should you need any assistance or if you'd like to provide feedback, don't hesitate to reach out to our dedicated support team in discord.
With LION by your side, your lesion segmentation adventures will be unstoppable! πΊπ
Dive in now and make PET tumor segmentation a seamless experience!
---
Thank you for trusting LION with your PET tumor segmentation needs. We're committed to providing you with top-notch tools and services that make your work easier and more efficient.
---
## **A Note on QIMP Python Packages: The 'Z' Factor ππ**
Every Python package at QIMP carries a unique mark β a distinctive 'Z' at the end of their names. This isn't just a quirk or a random choice. The 'Z' is emblematic, an insignia of our forward-leaning vision and unwavering dedication to continuous innovation.
Take, for instance, our LION package, dubbed 'lionz', pronounced "lion-zee". Now, one might wonder, why append a 'Z'?
In the expansive realm of science and mathematics, 'Z' is frequently invoked as a representation of the unexplored, the variables that are shrouded in mystery, or the ultimate point in a sequence. This mirrors our ethos at QIMP perfectly. We're inveterate boundary-pushers, ever eager to trek into the uncharted, always aligning ourselves with the vanguard of technological advancement. The 'Z' is a testament to this ethos. It symbolizes our ceaseless endeavor to transcend the conventional, to journey into the untouched, and to be the torchbearers of the future in medical imaging.
So, the next time you stumble upon a 'Z' in any of our package names, let it serve as a reminder of the zest for exploration and the spirit of discovery that fuels us. With QIMP, you're not merely downloading a tool; you're aligning yourself with a movement that aims to redefine the landscape of medical image processing. Let's soar into the realms of the 'Z' dimension, side by side! π
---
## Contributors β¨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tbody>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/LalithShiyam"><img src="https://avatars.githubusercontent.com/u/48599863?v=4?s=100" width="100px;" alt="Lalith Kumar Shiyam Sundar"/><br /><sub><b>Lalith Kumar Shiyam Sundar</b></sub></a><br /><a href="https://github.com/LalithShiyam/LION/commits?author=LalithShiyam" title="Code">π»</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mprires"><img src="https://avatars.githubusercontent.com/u/48754309?v=4?s=100" width="100px;" alt="Manuel Pires"/><br /><sub><b>Manuel Pires</b></sub></a><br /><a href="https://github.com/LalithShiyam/LION/commits?author=mprires" title="Code">π»</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Keyn34"><img src="https://avatars.githubusercontent.com/u/87951050?v=4?s=100" width="100px;" alt="Sebastian Gutschmayer"/><br /><sub><b>Sebastian Gutschmayer</b></sub></a><br /><a href="https://github.com/LalithShiyam/LION/commits?author=Keyn34" title="Code">π»</a></td>
</tr>
</tbody>
</table>
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
Raw data
{
"_id": null,
"home_page": null,
"name": "lionz",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "lesion segmentation, tumors, PET/CT, medical imaging",
"author": null,
"author_email": "Lalith Kumar Shiyam Sundar <lalith.shiyamsundar@meduniwien.ac.at>, Sebastian Gutschmayer <sebastian.gutschmayer@meduniwien.ac.at>, Manuel Pires <manuel.pires@meduniwien.ac.at>",
"download_url": "https://files.pythonhosted.org/packages/48/58/4427bdb12c43b4fdf54d2f640a8800119f806fbc7b5e37ac9686a413e2a4/lionz-0.19.5.tar.gz",
"platform": null,
"description": "\n## LION (Lesion segmentatION): Loud. Proud. Unbounded. \ud83e\udd81\n[](https://pepy.tech/projects/lionz)\n[](https://zenodo.org/badge/latestdoi/685935027)<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->\n[](https://www.gnu.org/licenses/gpl-3.0)\n[](mailto:lalith@zenta.solutions)\n\n\n\n\nLION has roared onto the scene, revolutionizing the way we view lesion segmentation. Born from the same lineage as lion 3.0, LION is laser-focused on tumor segmentation. Our curated models, each crafted with precision, cater to various tracers, setting the gold standard in lesion detection.\n\n\u2728 **Exclusive Engineering Paradigm**: With LION, segmentation is not just a task; it's an orchestrated dance of models. Define workflows for each model, mix and match channels as some models thrive on PET/CT while others are optimized for just PET or CT. Run them in a sequence that maximizes output and efficiency. This unique trait of LION lets you tailor the process to your exact needs, making lesion segmentation an art of precision.\n\n\n\ud83d\udd14 **Flexibility Unleashed**: Whether you're looking for a command-line tool for batch processing or a library package for your Python projects, LION has you covered. Seamlessly integrate it into your work environment and watch it shine.\n\nDive into the exciting world of PET tumor segmentation with LION and experience the future today!\n\n\ud83d\udd14 **Important Notification:** As of now, the LION tool is optimized and validated for FDG imaging. Development for PSMA imaging is ongoing and will be available soon. We appreciate your patience and understanding. Stay tuned for updates! \ud83d\udd14\n\n---\n\n## **Requirements** \u2705\n\nFor an optimal experience with LION, ensure the following:\n\n- **Operating System**: LION runs smoothly on Windows, Mac, or Linux.\n- **Memory**: At least 32GB of RAM ensures LION operates without a hitch.\n- **GPU**: For blazing-fast results, an NVIDIA GPU or an Apple MPS chip is highly recommended. But if you don't have one, fret not! LION will still get the job done, just at a more leisurely pace.\n- **Python**: Version 3.10!\n\n---\n\n## **Installation Guide** \ud83d\udee0\ufe0f\n\nNavigating the installation process is a breeze. Just follow the steps below:\n\n**For Linux and MacOS** \ud83d\udc27\ud83c\udf4f\n1. Create a Python environment, for example, 'lion-env'.\n```bash\npython3.10 -m venv lion-env\n```\n2. Activate your environment.\n```bash\nsource lion-env/bin/activate # for Linux\nsource lion-env/bin/activate # for MacOS\n```\n3. Install LION.\n```bash\npip install lionz\n```\n\n**From source using uv** \ud83e\uddd1\u200d\ud83d\udcbb\n\nIf you are working from a clone of this repository, the project is now managed with [uv](https://github.com/astral-sh/uv).\n\n```bash\n# inside the cloned repository\nuv sync\nuv run lionz -h\n```\n\nThe `uv sync` command creates a virtual environment, resolves dependencies using `pyproject.toml`, and produces a `uv.lock` so builds stay reproducible.\n## For Macs powered by Apple Silicon (M series chips with MPS) \ud83c\udf4f\n\n> Yes, it works. But you'll need to follow these steps carefully. Grab a \u2615 or \ud83c\udf7a \u2014 this may take a few minutes.\n> Note: Please make sure you have the right version of `cmake`, as well as `ninja` installed.\n> Also you need `git`, `xcode command line tools` installed. Using `brew` is the safest option. \n\n1. Create and activate a virtual environment (We recommend Python 3.10 for stability)\n\n ```bash\n python3.10 -m venv lion-env\n source lion-env/bin/activate\n ```\n\n2. Install lion and the MPS-compatible PyTorch fork\n\n You\u2019ll need a special PyTorch build tailored for Apple\u2019s Metal backend (MPS), which doesn\u2019t use CUDA.\n\n ```bash\n pip install lionz\n pip uninstall torch # ensures clean install; avoids conflicts with lion-installed version\n git clone https://github.com/LalithShiyam/pytorch-mps.git\n cd pytorch-mps\n ```\n\n4. Fix your CMake version (IMPORTANT \u26a0\ufe0f)\n\n **Do not use CMake 4.x** \u2014 it will break the build due to compatibility issues with `protobuf`.\n\n Check your version:\n\n ```bash\n cmake --version\n ```\n\n If it's **4.0 or higher**, downgrade to a compatible version (e.g., 3.29.2):\n\n ```bash\n pip uninstall cmake -y\n pip install cmake==3.29.2\n ```\n\n4. Build the custom PyTorch fork for MPS\n\n This will build PyTorch without CUDA (which Apple Silicon doesn\u2019t support anyway):\n \n ```bash\n USE_CUDA=0 python setup.py develop --verbose 2>&1 | tee build.log\n ```\n\n> \u2705 This may take some time. If it completes without errors, you\u2019re good to go.\n\n5. Patch `nnUNetTrainer.py` (one-time fix)\n\n Due to differences in PyTorch exports, `nnUNet` may crash with:\n\n ```\n ImportError: cannot import name 'GradScaler' from 'torch'\n ```\n\nTo fix it:\n\n1. Open the following file inside your lion-env folder:\n\n ```\n ~/lion-env/lib/python3.10/site-packages/nnunetv2/training/nnUNetTrainer/nnUNetTrainer.py\n ```\n\n2. Replace this line 43:\n\n ```python\n from torch import GradScaler\n ```\n\n with:\n\n ```python\n from torch.cuda.amp import GradScaler\n ```\n\u2705 That\u2019s it!\n\nNow you\u2019re ready to use **LION on Apple Silicon** with MPS acceleration. \ud83c\udfce\u26a1\nIf anything crashes, blame the silicon gods\u2026 or just open an issue. We're here to help.\n\n\n\n**For Windows** \ud83e\ude9f\n1. Set up a Python environment, say 'lion-env'.\n```bash\npython -m venv lion-env\n```\n2. Get your environment up and running.\n```bash\n.\\lion-env\\Scripts\\activate\n```\n3. Hop over to the PyTorch website and fetch the right version for your system. This step is crucial!\n4. Finish up by installing LION.\n```bash\npip install lionz\n```\n\n---\n\n## \ud83e\uddec Supported Models by Tracer Type\n\n| Tracer | Model Name | Status | Training Dataset Size | Cancer Type |\n|:------:|:----------:|:---------------------:|:------------------------------:|:------------------------------------------:|\n| FDG | `fdg` | \u2705 Stable & validated | 5,341 patients (multicenter) | `breast` `melanoma` `lung` `lymphoma` `colorectal` |\n| PSMA | `psma` | \ud83d\udd27 In development | ~1,200 patients (in progress) | `prostate` |\n\n---\n\n## **Usage Guide** \ud83d\udcda\n\n**Command-line Tool for Batch Processing** \ud83d\udcbb\n\nStarting with LION is as intuitive as it gets. Here's how:\n\n```bash\nlionz -d <path_to_image_dir> -m <model_name>\n```\nReplace `<path_to_image_dir>` with your image directory and `<model_name>` with your chosen segmentation model's name.\n\n**Real-Life Usage Example \ud83c\udf1f**\n\nTo run LION using the 'fdg' model on a batch of images located in `/path/to/dummy/image/directory`, you'd simply execute:\n\n```bash\nlionz -d /path/to/dummy/image/directory -m fdg\n```\n**Thresholding Feature \u2702\ufe0f** \n\nLION is also equipped with a thresholding feature to refine your segmentations. Just add -t and the value you want to use for thresholding. \n\n**Important:** Thresholding is only supported with DICOM or SUV NIfTI inputs! If you don't require thresholding, feel free to use any LION-compliant input.\n\nHere's how you can apply thresholding for SUV 2.5:\n```bash\nlionz -d /path/to/dummy/image/directory -m fdg -t 2.5\n```\n**Generating a MIP with overalayed segmentation**\n\nIf you want to have a quick glance at the segmentation by having a rotation MIP with the obtained segmentations overlayed all you need is to add the -gen-mip flag to your command.\n\n```bash\nlionz -d /path/to/dummy/image/directory -m fdg -gen-mip\n```\nAnd, if you ever find yourself needing some guidance:\n```bash\nlionz -h\n```\nThis trusty command will spill all the beans about available models and their specialties.\n\n### Using LION as a Library \ud83d\udce6\ud83d\udc0d\n\nLION isn't just a command-line powerhouse; it\u2019s also a flexible library for Python projects. Here\u2019s how to make the most of it:\n\nFirst, import the `lion` function from the `lionz` package in your Python script:\n\n ```python\nfrom lionz import lion\n ```\n\n#### *Calling the `lion` Function* \ud83e\udd8c\n\nThe `lion` function is versatile and accepts various input types. It takes five main arguments:\n\n1. `input`: The data to process, which can be:\n - A path to an input file or directory (NIfTI, either `.nii` or `.nii.gz`).\n - A tuple containing a NumPy array and its spacing (e.g., `numpy_array`, `(spacing_x, spacing_y, spacing_z)`).\n - A `SimpleITK` image object.\n2. `model_name`: The model name to use for segmentation.\n3. `output_dir`: The directory where the results will be saved.\n4. `accelerator`: The type of accelerator to use (`\"cpu\"`, `\"cuda\"`, or `\"mps\"` for Mac).\n5. `threshold`: The value to use for thresholding. Optional\n\n#### Examples \ud83d\udcc2\u2702\ufe0f\ud83d\udcbb\n\nHere are some examples to illustrate different ways to use the `lion` function:\n\n1. **Using a file path and multiple models:**\n ```python\n lion('/path/to/input/file', 'fdg', '/path/to/save/output', 'cuda', 2.5)\n ```\n\n2. **Using a NumPy array with spacing:**\n ```python\n lion((numpy_array, (1.5, 1.5, 1.5)), 'psma', '/path/to/save/output', 'cuda', 2.5)\n ```\n\n3. **Using a SimpleITK image:**\n ```python\n lion(simple_itk_image, 'fdg', '/path/to/save/output', 'cuda', 2.5)\n ```\n \n#### Usage of `lion()` in your code\nTo use the `lion()` function, ensure that you wrap the function call within a main guard to prevent recursive process creation errors:\n```python\nfrom lionz import lion\n\nif __name__ == '__main__':\n input_file = '/path/to/input/file'\n model = 'fdg'\n output_directory = '/path/to/save/output'\n accelerator = 'cuda'\n threshold = 2.5\n lion(input_file, models, output_directory, accelerator, threshold)\n```\n\n---\n\n## **Directory Conventions for LION** \ud83d\udcc2\ud83c\udff7\ufe0f\n\nFor batch mode users \u26a0\ufe0f, ensure your data structure and naming conventions align with the provided guidelines. LION is compatible with both DICOM and NIFTI formats. For DICOM, LION discerns the modality from tags. For NIFTI, file naming is key. Allowed modality tags: `PT` for PET, `CT` for CT as of now.\n\n**Directory Structure** \ud83c\udf33\n\nOrganize your dataset as follows:\n\n```\n\ud83d\udcc2 LION_data/\n\u2502\n\u251c\u2500\u2500 \ud83d\udcc1 Subject1\n\u2502 \u251c\u2500\u2500 \ud83d\udcc1 Modality1\n\u2502 \u2502 \u2514\u2500\u2500 \ud83d\udcc4 File1.dcm\n\u2502 \u2514\u2500\u2500 \ud83d\udcc1 Modality2\n\u2502 \u2514\u2500\u2500 \ud83d\udcc4 File2.dcm\n\u251c\u2500\u2500 \ud83d\udcc1 Subject2\n\u2502 \u2514\u2500\u2500 \ud83d\udcc4 Modality1_Subject2.nii\n\u2502 \u2514\u2500\u2500 \ud83d\udcc4 Modality2_Subject2.nii\n\u2514\u2500\u2500 \ud83d\udcc1 Subject3\n \u2514\u2500\u2500 \ud83d\udcc4 Modality1_Subject3.nii\n \u2514\u2500\u2500 \ud83d\udcc4 Modality2_Subject3.nii\n\n```\n## **Naming Conventions for NIFTI** \ud83d\udcdd\n\nEnsure you attach the correct modality as a prefix in the file name.\n\n\n\n\n---\n\n### Dataset Organization for FDG Model\n\nFor the FDG model, your dataset must be organized strictly according to the guidelines below, considering PT (Positron Emission Tomography) and CT (Computed Tomography) as the primary modalities:\n\n```\n\ud83d\udcc2 FDG_data/\n\u2502\n\u251c\u2500\u2500 \ud83d\udcc1 Patient1\n\u2502 \u2514\u2500\u2500 \ud83d\udcc1 AnyFolderNameForPT\n\u2502 \u251c\u2500\u2500 \ud83d\udcc4 DICOM_File1.dcm\n\u2502 \u251c\u2500\u2500 \ud83d\udcc4 DICOM_File2.dcm\n\u2502 \u2514\u2500\u2500 ...\n\u251c\u2500\u2500 \ud83d\udcc1 Patient2\n\u2502 \u2514\u2500\u2500 \ud83d\udcc4 PT_Patient2.nii\n\u2514\u2500\u2500 \ud83d\udcc1 Patient3\n \u2514\u2500\u2500 \ud83d\udcc4 PT_Patient3.nii.gz\n```\n\n**Important Guidelines:**\n\n- Each patient's data must be stored in a dedicated folder.\n- For DICOM format:\n - Patient1's example demonstrates the DICOM structure. Inside each patient's main folder, the inner folders can have any name for PT modality. Multiple DICOM files can be stored in these folders. The modality (PT) will be inferred from the DICOM's modality tag.\n- For NIFTI format:\n - Patient2 and Patient3 examples demonstrate the NIFTI structure. For these, PT modality is directly within the patient's folder with the `.nii` extension. Adjust the naming structure as per the specifics of your dataset if required.\n \n- Only DICOM and NIFTI formats are supported. No other imaging formats are allowed.\n- Adhering to these guidelines is non-negotiable for both FDG and PSMA models.\n\n\n\n---\n\n# \ud83d\udcc1 LIONz Output Folder Structure for FDG Model\n\nWhen you run the FDG model, an output folder named `lionz-fdg-<timestamp>` will be generated in the respective subject directory. Here's a breakdown of the folder structure:\n\n```\n\ud83d\udcc2 lionz-fdg-2023-09-18-10-07-25/\n\u2502\n\u2502\n\u251c\u2500\u2500 \ud83d\udcc2 PT\n\u2502 \u2514\u2500\u2500 \ud83d\udcc4 PT_0147.nii.gz\n\u2502\n\u251c\u2500\u2500 \ud83d\udcc2 segmentations\n\u2502 \u251c\u2500\u2500 \ud83d\udcc4 0147_no_tumor_seg.nii.gz\n\u2502 \u2514\u2500\u2500 \ud83d\udcfd 0147_rotational_mip.gif (optional)\n\u2502\n\u2514\u2500\u2500 \ud83d\udcc2 stats\n \u2514\u2500\u2500 \ud83d\udcc4 0147_metrics.csv\n```\n\n## \ud83d\udccc Breakdown:\n- \ud83d\udcc2 **segmentations**: Houses all segmentation-related files.\n - \ud83d\udcc4 NIFTI files showing segmentations.\n - \ud83d\udcfd GIF files representing various views. Only when requested by the user.\n- \ud83d\udcc2 **stats**: Contains `.csv` files with metrics related to the analysis.\n\n---\n\nHarness the power of LION and elevate your PET tumor segmentation game! \ud83d\ude80\ud83e\udd81\n\nRemember, the LION team is here to support you every step of the way. Should you need any assistance or if you'd like to provide feedback, don't hesitate to reach out to our dedicated support team in discord.\n\nWith LION by your side, your lesion segmentation adventures will be unstoppable! \ud83d\ude3a\ud83c\udf1f\n\nDive in now and make PET tumor segmentation a seamless experience!\n\n---\n\nThank you for trusting LION with your PET tumor segmentation needs. We're committed to providing you with top-notch tools and services that make your work easier and more efficient.\n\n\n\n---\n\n## **A Note on QIMP Python Packages: The 'Z' Factor \ud83d\udcda\ud83d\ude80**\n\nEvery Python package at QIMP carries a unique mark \u2013 a distinctive 'Z' at the end of their names. This isn't just a quirk or a random choice. The 'Z' is emblematic, an insignia of our forward-leaning vision and unwavering dedication to continuous innovation.\n\nTake, for instance, our LION package, dubbed 'lionz', pronounced \"lion-zee\". Now, one might wonder, why append a 'Z'?\n\nIn the expansive realm of science and mathematics, 'Z' is frequently invoked as a representation of the unexplored, the variables that are shrouded in mystery, or the ultimate point in a sequence. This mirrors our ethos at QIMP perfectly. We're inveterate boundary-pushers, ever eager to trek into the uncharted, always aligning ourselves with the vanguard of technological advancement. The 'Z' is a testament to this ethos. It symbolizes our ceaseless endeavor to transcend the conventional, to journey into the untouched, and to be the torchbearers of the future in medical imaging.\n\nSo, the next time you stumble upon a 'Z' in any of our package names, let it serve as a reminder of the zest for exploration and the spirit of discovery that fuels us. With QIMP, you're not merely downloading a tool; you're aligning yourself with a movement that aims to redefine the landscape of medical image processing. Let's soar into the realms of the 'Z' dimension, side by side! \ud83d\ude80\n\n---\n\n## Contributors \u2728\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n<!-- prettier-ignore-start -->\n<!-- markdownlint-disable -->\n<table>\n <tbody>\n <tr>\n <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"https://github.com/LalithShiyam\"><img src=\"https://avatars.githubusercontent.com/u/48599863?v=4?s=100\" width=\"100px;\" alt=\"Lalith Kumar Shiyam Sundar\"/><br /><sub><b>Lalith Kumar Shiyam Sundar</b></sub></a><br /><a href=\"https://github.com/LalithShiyam/LION/commits?author=LalithShiyam\" title=\"Code\">\ud83d\udcbb</a></td> \n <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"https://github.com/mprires\"><img src=\"https://avatars.githubusercontent.com/u/48754309?v=4?s=100\" width=\"100px;\" alt=\"Manuel Pires\"/><br /><sub><b>Manuel Pires</b></sub></a><br /><a href=\"https://github.com/LalithShiyam/LION/commits?author=mprires\" title=\"Code\">\ud83d\udcbb</a></td>\n <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"https://github.com/Keyn34\"><img src=\"https://avatars.githubusercontent.com/u/87951050?v=4?s=100\" width=\"100px;\" alt=\"Sebastian Gutschmayer\"/><br /><sub><b>Sebastian Gutschmayer</b></sub></a><br /><a href=\"https://github.com/LalithShiyam/LION/commits?author=Keyn34\" title=\"Code\">\ud83d\udcbb</a></td>\n </tr>\n </tbody>\n</table>\n\n<!-- markdownlint-restore -->\n<!-- prettier-ignore-end -->\n\n<!-- ALL-CONTRIBUTORS-LIST:END -->\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n",
"bugtrack_url": null,
"license": null,
"summary": "A toolkit for precise segmentation of tumors in PET/CT scans.",
"version": "0.19.5",
"project_urls": {
"Bug Tracker": "https://github.com/QIMP-Team/lionz/issues",
"Documentation": "https://lionz.readthedocs.io/en/latest/",
"Homepage": "https://github.com/QIMP-Team/lionz",
"Source": "https://github.com/QIMP-Team/lionz"
},
"split_keywords": [
"lesion segmentation",
" tumors",
" pet/ct",
" medical imaging"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "5e6cbe5688229eb96b0e7c7c88d2287feef35d83abcb594ffa366c03657bab24",
"md5": "f56dce8119abb174e1853bda8c252c30",
"sha256": "44d151b763360ffc6b2fd42a96d8696f0aa5d38517edd050786487be272b8ffe"
},
"downloads": -1,
"filename": "lionz-0.19.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f56dce8119abb174e1853bda8c252c30",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 55255,
"upload_time": "2025-11-03T13:30:13",
"upload_time_iso_8601": "2025-11-03T13:30:13.263340Z",
"url": "https://files.pythonhosted.org/packages/5e/6c/be5688229eb96b0e7c7c88d2287feef35d83abcb594ffa366c03657bab24/lionz-0.19.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "48584427bdb12c43b4fdf54d2f640a8800119f806fbc7b5e37ac9686a413e2a4",
"md5": "0ad008a5a81ac3a56efd8cce8228391d",
"sha256": "a5cb1938801b00e9f867ee7525b2de339a5273f6bf99294efd101a6ee7b7958b"
},
"downloads": -1,
"filename": "lionz-0.19.5.tar.gz",
"has_sig": false,
"md5_digest": "0ad008a5a81ac3a56efd8cce8228391d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 58295,
"upload_time": "2025-11-03T13:30:14",
"upload_time_iso_8601": "2025-11-03T13:30:14.443788Z",
"url": "https://files.pythonhosted.org/packages/48/58/4427bdb12c43b4fdf54d2f640a8800119f806fbc7b5e37ac9686a413e2a4/lionz-0.19.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-11-03 13:30:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "QIMP-Team",
"github_project": "lionz",
"github_not_found": true,
"lcname": "lionz"
}