https://github.com/imagingdatacommons/pyplastimatch
Python wrapper for Plastimatch.
https://github.com/imagingdatacommons/pyplastimatch
dicom-images medical-image-processing python
Last synced: 11 months ago
JSON representation
Python wrapper for Plastimatch.
- Host: GitHub
- URL: https://github.com/imagingdatacommons/pyplastimatch
- Owner: ImagingDataCommons
- License: bsd-3-clause
- Created: 2021-08-04T13:01:18.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-08-27T15:12:19.000Z (over 1 year ago)
- Last Synced: 2024-11-01T14:40:20.330Z (over 1 year ago)
- Topics: dicom-images, medical-image-processing, python
- Language: Jupyter Notebook
- Homepage: https://pypi.org/project/pyplastimatch/
- Size: 54.3 MB
- Stars: 11
- Watchers: 4
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PyPlastimatch
PyPlastimatch is a python wrapper for [Plastimatch](http://plastimatch.org/), an ITK-based open source software designed for volumetric medical image processing and radiation therapy applications.
The main reason behing the development of PyPlastimatch is being able to use the Plastimatch functions within python scripts without having to code using `os.system` or `subprocess` all the time. Also, we are working on making the output of some of the functions Plastimatch implements for evaluation (e.g., Dice Coefficient and Hausdorff Distance) more pythonic/easily usable in python-based data analysis pipelines.
Together with the wrapping functions, we are also developing simple but handy functions that can be used for quick data exploration (e.g., simple widgets based on ipywidgets) in ipython notebooks and JupyterLab.
PyPlastimatch is completely independent from the main software Plastimatch, and it is being developed mainly for internal use. For this reason, most of the Plastimatch functions might be missing. If you would like to see something added or point out how we could improve anything in the wrapper, you are very welcome to [open an issue at the issue page](https://github.com/AIM-Harvard/pyplastimatch/issues).
# Table of Contents
- [Install Via pip](#install-via-pip)
- [Dependencies](#dependencies)
- [Python](#python)
- [Plastimatch](#plastimatch)
- [dcmqi](#dcmqi)
- [Usage Example](#usage-example)
- [Run in a Docker Container](#ubuntu-2204-lts-plastimatch-docker-container)
- [Further Reading](#further-reading)
# Install Via `pip`
PyPlastimatch can be installed via pip:
```
pip install pyplastimatch
```
# Dependencies
## Python
If you decide to clone the PyPlastimatch repository and not to install it with `pip`, in order to run the code as intended, all the python libraries found in `requirements.txt` must be installed. This can be done running the command:
```
pip3 install -r requirements.txt
```
## Plastimatch
Since PyPlastimatch is a python wrapper and doesn't include any processing code, Plastimatch must be installed on the machine separately.
### Ubuntu 20.04 LTS
For users running Ubuntu 20.04 LTS (and distributions that fetch the same packages), Plastimatch can be installed simply by running:
```
sudo apt install plastimatch
```
### Ubuntu 22.04 LTS
Users running Ubuntu 22.04 LTS will unfortunately not be able to install Plastimatch via `apt` (see [this Issue on the official Plastimatch GitLab](https://gitlab.com/plastimatch/plastimatch/-/issues/87)). To remedy this, we compiled a binary file for Ubuntu 22.04 LTS that you can find [in our releases](https://github.com/AIM-Harvard/pyplastimatch/releases) and you can download running the following once PyPlastimatch is installed (from a Python3 shell):
```
from pyplastimatch.utils.install import install_precompiled_binaries
install_precompiled_binaries()
```
and, of course, its equivalent from CLI:
```
RUN python3 -c 'from pyplastimatch.utils.install import install_precompiled_binaries; install_precompiled_binaries()'
```
The plastimatch binary we provide was compiled dinamically, so it will not work without installing some dependencies (`itk` via `pip`, and some system dependencies that the `install_precompiled_binaries()` function takes care of automatically). Depending on the python version you are using and your environment (i.e., packages already installed), you might need to install `itk` via `pip` before installing `pyplastimatch`.
In the future, we might support binaries pre-compiled statically, and for other distributions/OSs.
### Other OSs
For Windows users, Plastimatch can be installed following [the guide at this webpage](http://plastimatch.org/windows_installation.html).
### Building from Source
Plastimatch can also be build from source following [the guide at this webpage](http://plastimatch.org/building_plastimatch.html). The guide could be slightly outdated, but it should be enough to get you started.
## DCMQI
Some functions might be based on the [DICOM for Quantitative Imaging (dcmqi) library](https://github.com/QIICR/dcmqi), that must be installed separately (e.g., under Linux, download the latest release, move the content of the `bin` folder under `usr/local/bin`, and make the files executable).
# Usage Example
You can try PyPlastimatch on Google Colab without installing anything. To open the Colab notebook, click here: [](https://colab.research.google.com/github/AIM-Harvard/pyplastimatch/blob/main/notebooks/pyplastimatch_MWE.ipynb)
Since Plastimatch and this wrapper are being used for the development of AI-base medical image analysis pipelines on the [NIH CRDC Imaging Data Commons](https://datacommons.cancer.gov/repository/imaging-data-commons) platform, some example notebooks using PyPlastimatch can be found at the [IDC-Examples/notebooks](https://github.com/ImagingDataCommons/IDC-Examples/tree/master/notebooks) repository as well.
Note: provided you have a Google Cloud Platform project correctly set up, you will be able to run this and all the other notebooks for free, entirely on the cloud. Should you find any issues with the notebooks or would like to learn more, you can get in touch here, on the IDC repositories, or the [IDC forum](https://discourse.canceridc.dev/).
# Ubuntu 22.04 LTS Plastimatch Docker Container
If you want to test Plastimatch for Ubuntu 22.04 LTS, you can use the Docker image we shared for this purpose under `dockerfiles`.
## Build the Docker Container
To build the Ubuntu 22.04 LTS Platimatch Docker container, run the following commands from the root of the PyPlastimatch repository:
```
cd dockerfiles/
docker build --tag pypla_22.04 . --no-cache
```
## Run the Docker Container
Assuming the data you want to convert/manipulate with Plastimatch is stored at `/home/dennis/Desktop/sample_data/`, the Docker command to run will look like the following
```
docker run --rm -it --entrypoint bash -v /home/dennis/Desktop/sample_data/:/app/data pypla_22.04
```
This will mount the data directory to the container's `/app/data` directory, and you can then run Plastimatch commands from within the container. For example, if `/home/dennis/Desktop/sample_data/` is structured as follows:
```
(base) dennis@W2-S1:~$ tree /home/dennis/Desktop/sample_data/ -L 1
/home/dennis/Desktop/sample_data/
└── dicom
```
Then, once inside the container, you can run the following command to convert the DICOM files to a volume saved in the NRRD format:
```
cd /app/data
plastimatch convert --input input_dcm/ --output-img test.nrrd
```
# Further Reading
[Paolo Zaffino's (un)"official" wrapper](https://gitlab.com/plastimatch/plastimatch/-/tree/master/extra/python).
Further discussion about the python-wrapping of Plastimatch can be found at [this discourse.slicer thread](https://discourse.slicer.org/t/python-wrapping-of-plastimatch/6722/10).