Skip to main content

read arbitrary medical images in python

Project description

pymedio

https://img.shields.io/pypi/v/pymedio.svg Documentation Status https://img.shields.io/pypi/pyversions/pymedio

Read arbitrary medical images in Python with various backends for scientific computing.

Basically, this package is just a modified version of torchio [1] and dicom-numpy which eagerly loads images (depending on the backend and settings) and returns them as numpy arrays (instead of PyTorch tensors, as is the case in torchio).

There are also various factory functions to load and work with images from memory buffers instead of from disk which is preferable in certain environments, e.g., AWS Lambda.

The main motivation for yet another medical image reader is that I wanted the flexibility of torchio in opening almost any medical image type, without requiring PyTorch and without the automatic casting of images to arrays of 32-bit floating point precision, which is an unnecessary and memory-intensive operation in many scientific computing use cases.

Install

The easiest way to install the package is through the following command:

pip install pymedio

To install from the source directory, clone the repo and run:

python setup.py install

The package only comes with pydicom installed by default; if you want to load non-DICOM images (using SimpleITK or nibabel as a backend), install with:

pip install "pymedio[all]"

Basic Usage

Say you have a directory of DICOM images at the path dicom_dir, then you can open it with:

import medio.dicom as miod
image = miod.DICOMImage.from_path("dicom_dir")

This uses pydicom as a backend to open the image à la dicom-numpy.

If you have a NIfTI image at image.nii, and you installed the package with all extras, you can open it with:

import medio.image as mioi
image = mioi.Image.from_path("image.nii")

In either case, you can proceed to work with the image data like a normal numpy array, e.g.,

image += 1.0
image *= image

You can convert an either image class to a torch tensor—if you have it installed—like:

import torch
tensor = torch.as_tensor(image.torch_compatible())

References

History

0.1.3 (2021-12-23)

  • Lazy load DICOM files to reduce peak memory consumption

  • Make DICOM and base image classes (more) immutable

0.1.2 (2021-12-22)

  • Make Image classes proper subclasses of ndarray

  • Add type hints to support normal numpy operations on Images

0.1.1 (2021-12-21)

  • Avoid version collision

0.1.0 (2021-12-21)

  • First release on PyPI.

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

pymedio-0.1.3.tar.gz (29.0 kB view hashes)

Uploaded Source

Built Distribution

pymedio-0.1.3-py3-none-any.whl (23.3 kB view hashes)

Uploaded Python 3

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