.
This commit is contained in:
+40
-1
@@ -6,6 +6,8 @@ from io import BytesIO
|
||||
from PIL import Image, ImageFile
|
||||
|
||||
import pydicom
|
||||
import sys
|
||||
import glob
|
||||
|
||||
try:
|
||||
from .pydicom_PIL import get_PIL_image
|
||||
@@ -71,4 +73,41 @@ def pil_dicom_image(source, exif_orientation=True, **options):
|
||||
def show_PIL(dataset):
|
||||
"""Display an image using the Python Imaging Library (PIL)"""
|
||||
im = get_PIL_image(dataset)
|
||||
im.show()
|
||||
im.show()
|
||||
|
||||
|
||||
|
||||
|
||||
def get_dicom_order(path):
|
||||
# load the DICOM files
|
||||
files = []
|
||||
|
||||
for fname in glob.glob(path, recursive=False):
|
||||
print("loading: {}".format(fname))
|
||||
files.append((fname, pydicom.dcmread(fname)))
|
||||
|
||||
print("file count: {}".format(len(files)))
|
||||
|
||||
# skip files with no SliceLocation (eg scout views)
|
||||
slices = []
|
||||
map = {}
|
||||
skipcount = 0
|
||||
for fname, f in files:
|
||||
print(dir(f))
|
||||
print(fname)
|
||||
if hasattr(f, 'SliceLocation'):
|
||||
slices.append(f)
|
||||
map[f.SliceLocation] = fname
|
||||
else:
|
||||
skipcount = skipcount + 1
|
||||
|
||||
print("skipped, no SliceLocation: {}".format(skipcount))
|
||||
|
||||
# ensure they are in the correct order
|
||||
slices = sorted(slices, key=lambda s: s.SliceLocation)
|
||||
|
||||
#print(slices)
|
||||
for i in slices:
|
||||
print(map[i.SliceLocation])
|
||||
|
||||
get_dicom_order("/home/ross/Downloads/DICOM HEAD/STD4/SER1/*.dcm")
|
||||
Reference in New Issue
Block a user