Commit f22dac26 authored by kulvait's avatar kulvait

Dicom directory listing

parent f25845b2
playground
__pycache__
*pyc
......@@ -10,6 +10,9 @@ DEN and DICOM IO manipulation
"""
import glob
import os
import pydicom
def timeToSeconds(naivetime):
strtime = str(naivetime).split('.', 1)[0]
......@@ -19,3 +22,20 @@ def timeToSeconds(naivetime):
hod = int(strtime[-6:][:2])
totalsec = sec + 60 * mins + 60 * 60 * hod
return(totalsec)
#Get list of pydicom objects for each file with given suffix in the directory
def getDicoms(d, suffixes=["IMA"]):
dicomFiles = []
for s in suffixes:
dicomFiles.extend(glob.glob(os.path.join(d, "*.%s"%s)))
dicomFiles = glob.glob(os.path.join(d, "*.IMA"))
dicoms = [pydicom.read_file(x) for x in dicomFiles]
return dicoms
def getPtsIds(dicoms):
patientIDs = list(set([x.PatientID for x in dicoms if "PatientID" in x.dir("PatientID")]))
return patientIDs
def getStudyDates(dicoms):
patientIDs = list(set([x.PatientID for x in dicoms if "StudyDate" in x.dir("StudyDate")]))
return patientIDs
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