Commit 6929d2c75c8d8d36e03aaefc96bcdb6736305623

Authored by tatiana
1 parent 35f8c809

ENC: New implementation of GetDicomFiles method, created GetSeries method

Showing 1 changed file with 39 additions and 15 deletions   Show diff stats
invesalius/reader/dicom_reader.py
@@ -31,13 +31,7 @@ from data.imagedata_utils import ResampleImage2D @@ -31,13 +31,7 @@ from data.imagedata_utils import ResampleImage2D
31 def LoadImages(dir_): 31 def LoadImages(dir_):
32 # TODO!!! SUPER GAMBIARRA!!! DO THIS BETTER 32 # TODO!!! SUPER GAMBIARRA!!! DO THIS BETTER
33 33
34 - if 0:  
35 - fow = vtk.vtkFileOutputWindow()  
36 - fow.SetFileName('vtk_output.txt')  
37 - ow = vtk.vtkOutputWindow ()  
38 - ow.SetInstance (fow)  
39 -  
40 - dcm_files, acquisition_modality = GetDicomFiles(dir_) 34 + dcm_files = GetDicomFiles(dir_)
41 35
42 dcm_series = dicom_grouper.DicomGroups() 36 dcm_series = dicom_grouper.DicomGroups()
43 dcm_series.SetFileList(dcm_files) 37 dcm_series.SetFileList(dcm_files)
@@ -70,9 +64,6 @@ def LoadImages(dir_): @@ -70,9 +64,6 @@ def LoadImages(dir_):
70 file_list.append(dicom.image.file) 64 file_list.append(dicom.image.file)
71 65
72 files = file_list 66 files = file_list
73 - print "*********"  
74 - print file_list  
75 - print "*********"  
76 spacing = dicom.image.spacing 67 spacing = dicom.image.spacing
77 68
78 #Coronal Crash. necessary verify 69 #Coronal Crash. necessary verify
@@ -128,7 +119,7 @@ def LoadImages(dir_): @@ -128,7 +119,7 @@ def LoadImages(dir_):
128 119
129 return image_data, dicom 120 return image_data, dicom
130 121
131 -def GetDicomFiles(path, recursive = False): 122 +def GetDicomFilesOld(path, recursive = False):
132 # TODO!!! SUPER GAMBIARRA!!! DO THIS BETTER 123 # TODO!!! SUPER GAMBIARRA!!! DO THIS BETTER
133 """ 124 """
134 Separate only files of a DICOM Determined 125 Separate only files of a DICOM Determined
@@ -136,7 +127,6 @@ def GetDicomFiles(path, recursive = False): @@ -136,7 +127,6 @@ def GetDicomFiles(path, recursive = False):
136 the directory. (recursive = True) 127 the directory. (recursive = True)
137 """ 128 """
138 result = [] 129 result = []
139 - acquisition_modality = None  
140 130
141 if (recursive == True): 131 if (recursive == True):
142 132
@@ -151,7 +141,6 @@ def GetDicomFiles(path, recursive = False): @@ -151,7 +141,6 @@ def GetDicomFiles(path, recursive = False):
151 read_dicom = dicom.Parser() 141 read_dicom = dicom.Parser()
152 if(read_dicom.SetFileName(path)): 142 if(read_dicom.SetFileName(path)):
153 if (read_dicom.GetImagePosition()): 143 if (read_dicom.GetImagePosition()):
154 - acquisition_modality = read_dicom.GetAcquisitionModality()  
155 result.append(path) 144 result.append(path)
156 else: 145 else:
157 files = glob.glob(path + os.sep + "*") 146 files = glob.glob(path + os.sep + "*")
@@ -159,6 +148,41 @@ def GetDicomFiles(path, recursive = False): @@ -159,6 +148,41 @@ def GetDicomFiles(path, recursive = False):
159 read_dicom = dicom.Parser() 148 read_dicom = dicom.Parser()
160 if (read_dicom.SetFileName(files[x])): 149 if (read_dicom.SetFileName(files[x])):
161 result.append(files[x]) 150 result.append(files[x])
162 - acquisition_modality = read_dicom.GetAcquisitionModality()  
163 # TODO!!! SUPER GAMBIARRA!!! DO THIS BETTER 151 # TODO!!! SUPER GAMBIARRA!!! DO THIS BETTER
164 - return result, acquisition_modality 152 + return result
  153 +
  154 +def GetSeries(path):
  155 + """
  156 + Return DICOM group of files inside given directory.
  157 + """
  158 + dcm_files = GetDicomFiles(path)
  159 +
  160 + dcm_series = dicom_grouper.DicomGroups()
  161 + dcm_series.SetFileList(dcm_files)
  162 + dcm_series.Update()
  163 +
  164 + return dcm_series.GetOutput()
  165 +
  166 +def GetDicomFiles(path):
  167 + """
  168 + Return all full paths to DICOM files inside given directory.
  169 + """
  170 + list_paths = os.walk(path)
  171 +
  172 + # Recursivelly, find all files inside this folder
  173 + file_list = []
  174 + for p in list_paths:
  175 + p_file_list = p[-1]
  176 + file_path = p[0]
  177 + for filename in p_file_list:
  178 + file_list.append(str(os.path.join(file_path,filename)))
  179 +
  180 + # Check if given file is in DICOM format
  181 + dicom_files = []
  182 + for file in file_list:
  183 + read_dicom = dicom.Parser()
  184 + if (read_dicom.SetFileName(file)):
  185 + dicom_files.append(file)
  186 +
  187 +
  188 + return dicom_files