Skip to main content

DICOM -> JPG/PNG/BMP/TIFF/ndarray

Project description

dicom2jpg

Converts DICOM to JPG/PNG/BMP/TIFF and numpy.ndarray

Installation

pip install dicom2jpg

Introdunction

import dicom2jpg

dicom_img_01 = "/Users/user/Desktop/img01.dcm"
dicom_dir = "/Users/user/Desktop/Patient_01"
export_location = "/Users/user/Desktop/BMP_files"

# convert single DICOM file to jpg format
dicom2jpg.dicom2jpg(dicom_img_01)  

# convert all DICOM files in dicom_dir folder to png format
dicom2jpg.dicom2png(dicom_dir)  

# convert all DICOM files in dicom_dir folder to bmp, to a specified location
dicom2jpg.dicom2bmp(dicom_dir, target_root=export_location) 

# convert single DICOM file to numpy.ndarray for further use
img_data = dicom2jpg.dicom2img(dicom_img_01)

# convert DICOM ByteIO to numpy.ndarray
img_data = dicom2jpg.io2img(dicomIO)

dicom2jpg converts DICOM images to JPG/PNG/BMP/TIFF formats and to numpy.ndarray. It piplines the lookup transformations by applying Modality LUT, VOI LUT, and Presentation LUT to the images, which makes output files looks like what we see on standard DICOM viewers.

dicom2jpg.dicom2jpg(origin, target_root=None, anonymous=False, multiprocessing=True)

dicom2jpg.dicom2png(origin, target_root=None, anonymous=False, multiprocessing=True)

dicom2jpg.dicom2bmp(origin, target_root=None, anonymous=False, multiprocessing=True)

dicom2jpg.dicom2tiff(origin, target_root=None, anonymous=False, multiprocessing=True)

  • origin can be a single DICOM file, a folder, or a list/tuple of file/folder

  • target_root would be the root folder of the first file/folder if not specified

  • exported files paths would be

    target_root / Today / PatientID_Filetype / StudyDate_StudyTime_Modality_AccNum / Ser_Img.Filetype

  • anonymous files paths would be

    target_root / Today / Patient_SerialNum / ModalitySerialNum_Modality / Ser_Img.Filetype

dicom2jpg.dicom2img(origin)

dicom2jpg.io2img(dicomIO)

  • converting dicom files or ByteIO to ndarray
  • ndarray is in 8 bit; RGB format if it's a color image

Image examples

CT MR CXR

Todo

  • Support multi-frame images
  • Image compression
  • Support overlays

Performance

  • Environment: Windows10, Jupyter Notebook, Python 3.8.10
  • 598MB 1873 files {'CT': 1528, 'CR': 52, 'MR': 174, 'DX': 36}
  • Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz. 4 Cores (hyper-threading off)
  • Tested on Ramdisk (no physical HDD was tortured :P)
multiprocessing anonymous duration (seconds)
False True 154.6-159.7
True True 79.2-82.9
False False 157.9-162.8
True False 56-58.5

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

dicom2jpg-0.1.10.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

dicom2jpg-0.1.10-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file dicom2jpg-0.1.10.tar.gz.

File metadata

  • Download URL: dicom2jpg-0.1.10.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.11.3 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.8.10

File hashes

Hashes for dicom2jpg-0.1.10.tar.gz
Algorithm Hash digest
SHA256 60976f1fb50df6b5a76c04b245e6aa78bcdb02d4c19cb6972b86a55e358a09a2
MD5 9da9549710837234bc341a522805063c
BLAKE2b-256 b9578a2f0094527979fb2fa2d3087736dd2d4375bb540ea9024ca59b4c092778

See more details on using hashes here.

File details

Details for the file dicom2jpg-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: dicom2jpg-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.11.3 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.8.10

File hashes

Hashes for dicom2jpg-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 a11e9b66c7343cae504fb607870c8192f91a425d3a68d3bb4df32e31b2185233
MD5 a60ee6ae7e78d1defcb9a8f45eca5b2a
BLAKE2b-256 adfe30a570e42fef84b6b6a3149a9adccb92a8422c385f931c9bd8f5021ed9b5

See more details on using hashes here.

Supported by

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