Skip to main content

Conversion of medical images to MHA and TIFF.

Project description

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.10, 3.11, 3.12, 3.13 or 3.14. 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
  • wsidicom
  • pyisyntax

Usage

panimg takes a directory 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 directory. 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 directories 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 directories you do not have a backup of.

panimg convert --input-dir /path/to/files/ --output-dir /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 .tif tiff
.tif .tif tiff
.svs (Aperio) .tif tiff
.vms, .vmu, .ndpi (Hamamatsu) .tif tiff
.scn (Leica) .tif tiff
.mrxs (MIRAX) .tif tiff
.biff (Ventana) .tif tiff
.dcm (DICOM-WSI) .tif tiff
.isyntax (iSyntax) .tif tiff 4

1: Detached headers are not supported.

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

3: 2D only, unitary dimensions

4: When isyntax is available in the python environment

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.file_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
    ...

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

panimg-0.17.0.tar.gz (57.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

panimg-0.17.0-py3-none-any.whl (52.1 kB view details)

Uploaded Python 3

File details

Details for the file panimg-0.17.0.tar.gz.

File metadata

  • Download URL: panimg-0.17.0.tar.gz
  • Upload date:
  • Size: 57.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for panimg-0.17.0.tar.gz
Algorithm Hash digest
SHA256 30c4889761e817379076a490efb5cfbf6aa2f05fea0e42aa57b3b51c8492f0f2
MD5 011d782b8098888bbd782967a0fbb0f9
BLAKE2b-256 a7c8bf4f5fbafaf1cde79df7d63958e333358ec3c9f9a6654df023fb2e8ce8d4

See more details on using hashes here.

File details

Details for the file panimg-0.17.0-py3-none-any.whl.

File metadata

  • Download URL: panimg-0.17.0-py3-none-any.whl
  • Upload date:
  • Size: 52.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for panimg-0.17.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c90f152ba6e68392d826f188750147ee37f0e27fdb026df657d3cb8b21f36a9f
MD5 0803ab5ead1ea70a68dd19c60089633c
BLAKE2b-256 f11abee995ddd756294ced98658b85219ca2f6a6de4892db88c28c873f362722

See more details on using hashes here.

Supported by

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