Convert DICOM files from DXA scans to other image formats, and parse the corresponding metadata files
Originally intended for DXA scans, but can also be used on any other DICOM formatted image as well (i.e. MRI).
Convert .dcm files to .jpg (or .png), preview images via matplotlib, and convert each file's corresponding metadata to a .txt file. Organize the output by anatomy (built in extensions compatible with dicom files from the United Kingdom National Health Service). Example dicom files used in this repo can be found here as "eg_20158_dxa.zip".
This code builds upon the pydicom library and OpenCV libraries. Please refer here and here for additional information on dependencies, the pydicom and opencv documentation.
# while in a directory that contains all dicom images, use this command to convert them to JPGs in a new directory
python dxaconv.py dicom_directory jpg_directory
If one of the files could not be converted for some reason, the following message will be displayed 'An exception occurred and a dcm file of this directory did not successfully convert:' preceding the error message.
# specify the path to a directory with dicom images, and the anatomy to filter by
python organizer.py dicom_directory spine
# it will output a text file containing all filenames for images of the spine
hip1, hip2, knee1, knee2, spine, thoracic, full_body_opaque, full_body_transparent
TODO
- Add DICOM to NIFTI conversion tool