Skip to main content

Tool for converting wsi-files to DICOM

Project description

wsidicomizer

wsidicomizer is a Python library for converting files wsi files to DICOM. The aims of the project are:

  • Provide lossless conversion for files supported by opentile.
  • Provide 'as good as possible' conversion for other formats.
  • Simplify the encoding of wsi metadata into DICOM.

Supported formats

wsidicomizer currently supports the following formats:

  • Aperio svs (lossless)
  • Hamamatsu ndpi (lossless)
  • Hamamatsu vms (lossy)
  • Philips tiff (lossless)
  • Mirax mrxs (lossy)
  • Trestle tiff (lossy)
  • Ventana bif (lossy)
  • Zeiss czi (lossy, only base level)

Installation

Download wsidicomizer from git

pip install wsidicomizer

Install OpenSlide Instructions for how to install OpenSlide is avaiable on https://openslide.org/download/ For Windows, you need also need add OpenSlide's bin-folder to the environment variable 'Path'

Install libjpeg-turbo Install libjpeg-turbo either as binary from https://libjpeg-turbo.org/ or using your package manager. For Windows, you also need to add libjpeg-turbo's bin-folder to the environment variable 'Path'

Important note

Please note that this is an early release and the API is not frozen yet. Function names and functionality is prone to change.

Requirements

wsidicomizer requires python >=3.7 and uses numpy, pydicom, highdicom, imagecodecs, openslide-python, PyTurboJPEG, opentile, and wsidicom.

Limitations

Files with z-stacks or multiple focal paths are currently not supported. DICOM properties related to slice thickness, focal plane thickness, and imaged volume are saved as 0 and not with proper values.

Basic cli-usage

Convert a wsi-file into DICOM using cli-interface

wsidicomizer -i 'path_to_wsi_file' -o 'path_to_output_folder'

Arguments

-i, --input, path to input wsi file
-o, --output, path to output folder
-t, --tile-size, required depending on input format
-d, --dataset, optional path to json file defining base dataset
-l, --levels, optional levels to include
-w, --workers, number of threads to use
--chunk-size, number of tiles to give each worker at a time
--format, encoding format to use if re-encoding. 'jpeg' or 'jpeg2000'
--quality, quality to use if re-encoding.
--subsampling, subsampling option to use if re-encoding.

Flags

--no-label, do not include label(s)
--no-overview, do not include overview(s)
--no-confidential, do not include confidential metadata from image

Using the no-confidential-flag properties according to DICOM Basic Confidentiality Profile are not included in the output file. Properties otherwise included are currently:

  • Acquisition DateTime
  • Device Serial Number

Basic notebook-usage

Create module datasets (Optional)

from wsidicomizer.dataset import create_device_module, create_sample, create_specimen_module, create_brightfield_optical_path_module, create_patient_module, create_study_module
device_module = create_device_module(
    manufacturer='Scanner manufacturer',
    model_name='Scanner model name',
    serial_number='Scanner serial number',
    software_versions=['Scanner software versions']
)
sample = create_sample(
    sample_id='sample id',
    embedding_medium='Paraffin wax',
    fixative='Formalin',
    stainings=['hematoxylin stain', 'water soluble eosin stain']
)
specimen_module = create_specimen_module(
    slide_id='slide id',
    samples=[sample]
)
optical_module = create_brightfield_optical_path_module()
patient_module = create_patient_module()
study_module = create_study_module()

Convert a wsi-file into DICOM using python-interface

from wsidicomizer import WsiDicomizer
created_files = WsiDicomizer.convert(
    path_to_wsi_file,
    path_to_output_folder,
    [device_module, specimen_module, optical_module, patient_module, study_module],
    tile_size
)

tile_size is required for Ndpi- and OpenSlide-files.

Import a wsi file as a WsiDicom object.

from wsidicomizer import WsiDicomizer
wsi = WsiDicomizer.open(path_to_wsi_file)
region = wsi.read_region((1000, 1000), 6, (200, 200))
wsi.close()

Other DICOM python tools

Contributing

We welcome any contributions to help improve this tool for the WSI DICOM community!

We recommend first creating an issue before creating potential contributions to check that the contribution is in line with the goals of the project. To submit your contribution, please issue a pull request on the imi-bigpicture/wsidicomizer repository with your changes for review.

Our aim is to provide constructive and positive code reviews for all submissions. The project relies on gradual typing and roughly follows PEP8. However, we are not dogmatic. Most important is that the code is easy to read and understand.

TODOs

  • Packaging of libjpeg-turbo into an 'ready-to-use' distribution.

  • Look into if OpenSlide python will provide a 'ready-to-use' distribution.

  • Interface for coding annotations (geometrical, diagnosis using for example structured reporting).

Acknowledgement

wsidicomizer: Copyright 2021 Sectra AB, licensed under Apache 2.0.

This project is part of a project that has received funding from the Innovative Medicines Initiative 2 Joint Undertaking under grant agreement No 945358. This Joint Undertaking receives support from the European Union’s Horizon 2020 research and innovation programme and EFPIA. IMI website: www.imi.europa.eu

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

wsidicomizer-0.7.0.tar.gz (28.4 kB view details)

Uploaded Source

Built Distribution

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

wsidicomizer-0.7.0-py3-none-any.whl (33.1 kB view details)

Uploaded Python 3

File details

Details for the file wsidicomizer-0.7.0.tar.gz.

File metadata

  • Download URL: wsidicomizer-0.7.0.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.8.9 Windows/10

File hashes

Hashes for wsidicomizer-0.7.0.tar.gz
Algorithm Hash digest
SHA256 e9f061c4bb8917521e1ed2d09cf46abce9ffc226f7420d64f46cec59ebdfa5fa
MD5 914745f6a9e02b2388a8441929a69c9b
BLAKE2b-256 c81c80fdf6c7dad5ea7a9d2b35ac42394fc17888261e2264503b65a91b6fa346

See more details on using hashes here.

File details

Details for the file wsidicomizer-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: wsidicomizer-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 33.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.8.9 Windows/10

File hashes

Hashes for wsidicomizer-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 585f948b746bb587a7e2a6c3184d2457330665078dd7ce650fa06d2ccd69a03e
MD5 a1dc42c1396fa5497f7fc79e06e554ae
BLAKE2b-256 9687010bc1598065ef7f6bd3bdc42ebc25c231c4cd25f4a6ea5af0cd9f199df1

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