Git Product home page Git Product logo

rse-panimg's Introduction

panimg

CI PyPI PyPI - Python Version Code style: black DOI

NOT FOR CLINICAL USE

Conversion of medical images to MHA and TIFF. Requires Python 3.7, 3.8, 3.9 or 3.10. libvips-dev and libopenslide-dev must be installed on your system.

Under the hood we use:

  • SimpleITK
  • pydicom
  • pylibjpeg
  • Pillow
  • openslide-python
  • pyvips
  • oct-converter

Usage

panimg takes a folder and tries to convert the containing files to MHA or TIFF. By default, it will try to convert files from subdirectories as well. To only convert files in the top level directory, set recurse_subdirectories to False. It will try several strategies for loading the contained files, and if an image is found it will output it to the output folder. It will return a structure containing information about what images were produced, what images were used to form the new images, image metadata, and any errors from any of the strategies.

NOTE: Alpha software, do not run this on folders you do not have a backup of.

from pathlib import Path
from panimg import convert

result = convert(
    input_directory=Path("/path/to/files/"),
    output_directory=Path("/where/files/will/go/"),
)

Command Line Interface

panimg is also accessible from the command line. Install the package from pip as before, then you can use:

NOTE: Alpha software, do not run this on folders you do not have a backup of.

panimg convert /path/to/files/ /where/files/will/go/

To access the help test you can use panimg -h.

Supported Formats

Input Output Strategy Notes
.mha .mha metaio
.mhd with .raw or .zraw .mha metaio
.dcm .mha dicom
.nii .mha nifti
.nii.gz .mha nifti
.nrrd .mha nrrd 1
.e2e .mha oct 2
.fds .mha oct 2
.fda .mha oct 2
.png .mha fallback 3
.jpeg .mha fallback 3
.tiff .tiff tiff
.svs (Aperio) .tiff tiff
.vms, .vmu, .ndpi (Hamamatsu) .tiff tiff
.scn (Leica) .tiff tiff
.mrxs (MIRAX) .tiff tiff
.biff (Ventana) .tiff tiff

1: Detached headers are not supported.

2: Only OCT volume(s), no fundus image(s) will be extracted.

3: 2D only, unitary dimensions

Post Processors

You can also define a set of post processors that will operate on each output file. Post processors will not produce any new image entities, but rather add additional representations of an image, such as DZI or thumbnails. We provide a dzi_to_tiff post processor that is enabled by default, which will produce a DZI file if it is able to. To customise the post processors that run you can do this with

result = convert(..., post_processors=[...])

You are able to run the post processors directly with

from panimg import post_process
from panimg.models import PanImgFile

result = post_process(image_files={PanImgFile(...), ...}, post_processors=[...])

Using Strategies Directly

If you want to run a particular strategy directly which returns a generator of images for a set of files you can do this with

files = {f for f in Path("/foo/").glob("*.dcm") if f.is_file()}

try:
    for result in image_builder_dicom(files=files):
        sitk_image = result.image
        process(sitk_image)  # etc. you can also look at result.name for the name of the file,
                             # and result.consumed_files to see what files were used for this image
except UnconsumedFilesException as e:
    # e.errors is keyed with a Path to a file that could not be consumed,
    # with a list of all the errors found with loading it,
    # the user can then choose what to do with that information
    ...

rse-panimg's People

Contributors

jmsmkn avatar pkcakeout avatar mikeoverkamp-diag avatar harmvz avatar nlessmann avatar miriam-groeneveld avatar amickan avatar chrisvanrun avatar haimasree avatar silvandeleemput avatar cjacobs1 avatar karelger avatar njmhendrix avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.