.
This commit is contained in:
+35
-1
@@ -110,4 +110,38 @@ def get_dicom_order(path):
|
||||
for i in slices:
|
||||
print(map[i.SliceLocation])
|
||||
|
||||
#get_dicom_order("/home/ross/Downloads/DICOM HEAD/STD4/SER1/*.dcm")
|
||||
#get_dicom_order("/home/ross/Downloads/DICOM HEAD/STD4/SER1/*.dcm")
|
||||
|
||||
def pretty_print_dicom(dataset, indent=0):
|
||||
return "\n<br/>".join(print_dicom(dataset, indent))
|
||||
|
||||
|
||||
def print_dicom(dataset, indent=0):
|
||||
"""Go through all items in the dataset and print them with custom format
|
||||
|
||||
Modelled after Dataset._pretty_str()
|
||||
"""
|
||||
dont_print = ['Pixel Data', 'File Meta Information Version']
|
||||
|
||||
indent_string = " " * indent
|
||||
next_indent_string = " " * (indent + 1)
|
||||
|
||||
l = []
|
||||
|
||||
for data_element in dataset:
|
||||
if data_element.VR == "SQ": # a sequence
|
||||
l.append(f"({indent_string}{data_element.name}")
|
||||
for sequence_item in data_element.value:
|
||||
l.append(print_dicom(sequence_item, indent + 1))
|
||||
l.append(next_indent_string + "---------")
|
||||
else:
|
||||
if data_element.name in dont_print:
|
||||
l.append("""<item not printed -- in the "don't print" list>""")
|
||||
else:
|
||||
repr_value = repr(data_element.value)
|
||||
if len(repr_value) > 50:
|
||||
repr_value = repr_value[:50] + "..."
|
||||
l.append("{0:s} {1:s} = {2:s}".format(indent_string,
|
||||
data_element.name,
|
||||
repr_value))
|
||||
return l
|
||||
Reference in New Issue
Block a user