Commit 0b06f0e4 authored by Dominic Couture's avatar Dominic Couture

Add ability to read dose information from overlay of Siemens Dicom files

parent 8ebbdac4
......@@ -39,11 +39,28 @@ column_width = {
manufacturers_dict = {
'GE MEDICAL SYSTEMS': 'GE',
'': 'GE',
'SIEMENS': 'GE',
'GE': 'GE',
'SIEMENS': 'Siemens',
'Toshiba': 'Toshiba'}
def get_array_from_overlay(dcm):
""" Return a 2D numpy array of the overlay of index 1 for the given DICOM file.
Usefull to extract dose informaiton from `Siemens MedCom Object Graphics`.
"""
from dicom import tag
rows = dcm[tag(0x60000010)].value
cols = dcm[tag(0x60000011)].value
overlay_raw = dcm[tag(0x60003000)].value
n_bits = int(rows * cols / len(overlay_raw))
decoded_linear = np.zeros(rows * cols)
for i in range(1, len(overlay_raw)):
bits = tuple(int(j) for j in format(overlay_raw[i], '08b'))[::-1]
for k in range (0, n_bits):
decoded_linear[i * n_bits + k] = bits[k]
return np.reshape(decoded_linear, [rows, cols])
def read_column(array, limits, name):
""" Use OCR to read the content of an image and return a list of strings. `limits` is
a tuple containing the limits of the column in the format (top, bottom, left, right).
......@@ -63,16 +80,19 @@ def read_column(array, limits, name):
def read_dicom(dcm):
""" Return a dictionary with information extracted from the DICOM image.
"""
ds = dicom.read_file(join(dicom_dir, dcm))
dcm = dicom.read_file(join(dicom_dir, dcm))
manufacturer = manufacturers_dict[ds.Manufacturer]
limits = column_width[manufacturer]
info = {i: read_column(ds.pixel_array, limits[i], i) for i in limits}
if manufacturer == 'GE':
info = {i: read_column(ds.pixel_array, limits[i], i) for i in limits}
series = [{
'Series': int(i + 2),
'Type': info['Type'][i + 1],
'CTDIvol': float(info['CTDIvol'][i]),
'DLP': float(info['DLP'][i])} for i in range(len(info['DLP']) - 1)]
elif manufacturer == 'Siemens':
pixel_array = get_array_from_overlay(dcm)
info = {i: read_column(ds.pixel_array, limits[i], i) for i in limits}
return {'Total_DLP': float(info['DLP'][-1]), 'Series': series}
dicom_dir = '/Users/Dominic/Desktop/Dose_Reports'
......
from pydicom import read_file
from pydicom.tag import Tag
from sys import argv
import numpy as np
import matplotlib.pyplot as plt
def get_array_from_overlay(dcm):
""" Return a 2D numpy array of the overlay of index 1 for the given DICOM file.
Usefull to extract dose informaiton from `Siemens MedCom Object Graphics`.
"""
rows = dcm[Tag(0x60000010)].value
cols = dcm[Tag(0x60000011)].value
overlay_raw = dcm[Tag(0x60003000)].value
n_bits = int(rows * cols / len(overlay_raw))
decoded_linear = np.zeros(rows * cols)
for i in range(1, len(overlay_raw)):
bits = tuple(int(j) for j in format(overlay_raw[i], '08b'))[::-1]
for k in range (0, n_bits):
decoded_linear[i * n_bits + k] = bits[k]
return np.reshape(decoded_linear, [rows, cols])
dcm = read_file(argv[-1])
overlay = get_array_from_overlay(dcm)
plt.imshow(overlay)
plt.show()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment