Skip to main content

Med-Imagetools: Transparent and Reproducible Medical Image Processing Pipelines in Python

Project description

Med-Imagetools: Transparent and Reproducible Medical Image Processing Pipelines in Python

CI/CD Status GitHub repo size GitHub contributors GitHub stars GitHub forks Documentation Status DOI Status

PyPI - Python Version PyPI - Version Pre-Release

PyPI - Format Downloads

Latest Updates Nov 21st, 2024

New CLI entry point imgtools

imgtools

Feature: DICOMSort

[!WARNING] Warning: This feature is still in beta. Use with caution and report any issues on GitHub.

alt text

Latest Updates (v1.2.0) - Feb 5th, 2024

  • Documentation is now available at: https://med-imagetools.readthedocs.io
  • Dependencies have been reduced for a lighter install. torch and torchio dependencies have been moved to an extra pip install flag. Use pip install med-imagetools[torch] to use the Dataset feature and

Med-ImageTools core features

  • AutoPipeline CLI
  • nnunet nnU-Net compatibility mode
  • Built-in train/test split for both normal/nnU-Net modes
  • random_state for reproducible seeds
  • Region of interest (ROI) yaml dictionary intake for RTSTRUCT processing
  • Markdown report output post-processing
  • continue_processing flag to continue autopipeline
  • dry_run flag to only crawl the dataset

Med-Imagetools, a python package offers the perfect tool to transform messy medical dataset folders to deep learning ready format in few lines of code. It not only processes DICOMs consisting of different modalities (like CT, PET, RTDOSE and RTSTRUCTS), it also transforms them into deep learning ready subject based format taking the dependencies of these modalities into consideration.

Introduction

A medical dataset, typically contains multiple different types of scans for a single patient in a single study. As seen in the figure below, the different scans containing DICOM of different modalities are interdependent on each other. For making effective machine learning models, one ought to take different modalities into account.

Fig.1 - Different network topology for different studies of different patients

Med-Imagetools is a unique tool, which focuses on subject based Machine learning. It crawls the dataset and makes a network by connecting different modalities present in the dataset. Based on the user defined modalities, med-imagetools, queries the graph and process the queried raw DICOMS. The processed DICOMS are saved as nrrds, which med-imagetools converts to torchio subject dataset and eventually torch dataloader for ML pipeline.

Fig.2 - Med-Imagetools AutoPipeline diagram

Installing med-imagetools

pip install med-imagetools

(recommended) Create new conda virtual environment

conda create -n mit
conda activate mit
pip install med-imagetools

(optional) Install in development mode

conda create -n mit
conda activate mit
pip install -e git+https://github.com/bhklab/med-imagetools.git

This will install the package in editable mode, so that the installed package will update when the code is changed.

Getting Started

Med-Imagetools takes two step approch to turn messy medical raw dataset to ML ready dataset.

  1. Autopipeline: Crawls the raw dataset, forms a network and performs graph query, based on the user defined modalities. The relevant DICOMS, get processed and saved as nrrds
    autopipeline\
      [INPUT DIRECTORY] \
      [OUTPUT DIRECTORY] \
      --modalities [str: CT,RTSTRUCT,PT] \
      --spacing [Tuple: (int,int,int)]\
      --n_jobs [int]\
      --visualize [flag]\
      --nnunet [flag]\
      --train_size [float]\
      --random_state [int]\
      --roi_yaml_path [str]\
      --continue_processing [flag]\
      --dry_run [flag]
    
  2. class Dataset: This class converts processed nrrds to torchio subjects, which can be easily converted to torch dataset
    from imgtools.io import Dataset
    
    subjects = Dataset.load_from_nrrd(output_directory, ignore_multi=True)
    data_set = tio.SubjectsDataset(subjects)
    data_loader = torch.utils.data.DataLoader(data_set, batch_size=4, shuffle=True, num_workers=4)
    

Demo (Outdated as of v0.4)

These google collab notebooks will introduce the main functionalities of med-imagetools. More information can be found here

Tutorial 1: Forming Dataset with med-imagetools Autopipeline

Google Colab

Tutorial 2: Machine Learning with med-imagetools and torchio

Google Colab

Contributors

Thanks to the following people who have contributed to this project:

Contact

If you have any questions/concerns, you can reach the following contributors at sejin.kim@uhnresearch.ca

License

This project uses the following license: MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

med_imagetools-1.8.0.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

med_imagetools-1.8.0-py3-none-any.whl (94.2 kB view details)

Uploaded Python 3

File details

Details for the file med_imagetools-1.8.0.tar.gz.

File metadata

  • Download URL: med_imagetools-1.8.0.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for med_imagetools-1.8.0.tar.gz
Algorithm Hash digest
SHA256 794b3a6d73d4bac6c2f86aff3dfe4a79cca095c97b2d3b3789408d0e969e624a
MD5 b2df353d3ffe0296a75fc37fb680733c
BLAKE2b-256 69924d758275330fa79215a2a853607161bde7fcff8d9b03c754f3fdd668f01f

See more details on using hashes here.

File details

Details for the file med_imagetools-1.8.0-py3-none-any.whl.

File metadata

File hashes

Hashes for med_imagetools-1.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 41bf7929d50576e14ef823f751a70870e9bbf36e95ba04f7e025034a06615ea5
MD5 8a1f8902ed52bf7ab907ae27bdaf35b3
BLAKE2b-256 54dbc2332f1dc73680c854a9b9d8d4f86635d7758a7cd2ded2aa8cf14b86287c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page