Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

panimg

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

panimg

Conversion of medical images to MHA and TIFF.

  • 0.14.0
  • PyPI
  • Socket score

Maintainers
1

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.9, 3.10, 3.11, 3.12 or 3.13. 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

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 /path/to/files/ /where/files/will/go/

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

Supported Formats

InputOutputStrategyNotes
.mha.mhametaio
.mhd with .raw or .zraw.mhametaio
.dcm.mhadicom
.nii.mhanifti
.nii.gz.mhanifti
.nrrd.mhanrrd1
.e2e.mhaoct2
.fds.mhaoct2
.fda.mhaoct2
.png.mhafallback3
.jpeg.mhafallback3
.tiff.tifftiff
.svs (Aperio).tifftiff
.vms, .vmu, .ndpi (Hamamatsu).tifftiff
.scn (Leica).tifftiff
.mrxs (MIRAX).tifftiff
.biff (Ventana).tifftiff
.dcm (DICOM-WSI).tifftiff

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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc