Last updated:
0 purchases
pyplastimatch 0.4.6
PyPlastimatch
PyPlastimatch is a python wrapper for Plastimatch, 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.
Table of Contents
Install Via pip
Dependencies
Python
Plastimatch
dcmqi
Usage Example
Run in a Docker Container
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). To remedy this, we compiled a binary file for Ubuntu 22.04 LTS that you can find in our 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.
Building from Source
Plastimatch can also be build from source following the guide at this webpage. 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, 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:
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 platform, some example notebooks using PyPlastimatch can be found at the IDC-Examples/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.
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.
Further discussion about the python-wrapping of Plastimatch can be found at this discourse.slicer thread.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.