Skip to main content

panimg

CI PyPI Python Version from PEP 621 TOML Code style: black DOI

NOT FOR CLINICAL USE

Conversion of medical images to MHA and TIFF. Requires Python 3.11, 3.12, 3.13, 3.14 or 3.15. 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.

Each strategy runs in a separate process, so a crash in a native library (e.g. a segfault in SimpleITK on a malformed file) is reported as an error for the files that strategy was processing, rather than terminating your process. Those files are then passed on to the remaining strategies. Any custom strategies passed to convert must therefore be picklable (i.e. module level functions), and logging configuration is not carried over to the child process. As with other multiprocessing start methods than fork, the main module of your program is imported in the child process, so it must be importable and guard any work with if __name__ == "__main__":.

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

Metadata

Release files for panimg 0.20.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for panimg 0.20.0
File Size Uploaded Provenance Actions
panimg-0.20.0.tar.gz 59.0 kB With provenance Details for panimg-0.20.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for panimg 0.20.0
File Interpreter ABI Platform Actions
panimg-0.20.0-py3-none-any.whl Python 3 none any Details for panimg-0.20.0-py3-none-any.whl

Total release size: 112.1 kB

Release files / panimg-0.20.0.tar.gz

Download URL panimg-0.20.0.tar.gz
Size 59.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b8ca57cabdf24e66a0549f6ee2dddb5bfaabe2190937893955ea098b60586959
BLAKE2b-256 checksum
How to use checksums
f2789983e1f2cb0c68d38e1f5c01c059bcb052ac5750e52ee1375ac79f7f2dfc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / panimg-0.20.0-py3-none-any.whl

Download URL panimg-0.20.0-py3-none-any.whl
Size 53.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6ac2d552ef26148b51e020bb3921386c0e92c09afd5e57d7193adb0a2f8cc1d6
BLAKE2b-256 checksum
How to use checksums
f9cdc52b83847cce188063c200f91b5b37bfbaef8ae17af7c8d1ca61ed8a5269
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Security for panimg 0.20.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for panimg-0.20.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.20.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page