Created
July 31, 2017 06:25
-
-
Save yobayob/8ebc0ab6ccfcf5c1fea5a3af4170dd95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import dicom | |
import os | |
dicomdir = "~/Downloads/test/CDROM/DICOMDIR" | |
ds = dicom.read_dicomdir(dicomdir) | |
pixel_data = list() | |
for record in ds.DirectoryRecordSequence: | |
if record.DirectoryRecordType == "IMAGE": | |
# Extract the relative path to the DICOM file | |
path = os.path.join(os.path.dirname(dicomdir), *record.ReferencedFileID) | |
dcm = dicom.read_file(path) | |
# Now get your image data | |
pixel_data.append(dcm.pixel_array) | |
for ds in pixel_data: | |
plt.imshow(ds, cmap=plt.cm.bone) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment