Thursday, June 26, 2014

Reading DICOM files in Python 3

In Python 3, dicom files can be read, analysied and processed using Wand which is Python binding for ImageMagic. The example below shows how to get medical and image date embedded in DICOM and also how to disply the image itself.
from wand.image import Image
from wand.display import display
in_file = 'some_dicom_file.dcm'
with Image(filename=in_file) as img:
# show metadata for DICOM, such as dates, patient info, resolution, etc.
for k, v in img.metadata.items():
print(k,v)
# display the image
display(img)