Commit e95a97e6a528dc9c03fb39713b51239eed862fa2
1 parent
31c79184
Exists in
master
and in
67 other branches
ENH: Optimize time of importation
Showing
1 changed file
with
18 additions
and
24 deletions
Show diff stats
invesalius/reader/dicom_reader.py
@@ -158,11 +158,13 @@ def GetImageOrientationLabel(filename): | @@ -158,11 +158,13 @@ def GetImageOrientationLabel(filename): | ||
158 | else: | 158 | else: |
159 | return "" | 159 | return "" |
160 | 160 | ||
161 | +grouper = dicom_grouper.DicomPatientGrouper() | ||
161 | 162 | ||
162 | def GetDicomGroups(directory, recursive=True, gui=True): | 163 | def GetDicomGroups(directory, recursive=True, gui=True): |
163 | """ | 164 | """ |
164 | Return all full paths to DICOM files inside given directory. | 165 | Return all full paths to DICOM files inside given directory. |
165 | """ | 166 | """ |
167 | + | ||
166 | nfiles = 0 | 168 | nfiles = 0 |
167 | # Find total number of files | 169 | # Find total number of files |
168 | if recursive: | 170 | if recursive: |
@@ -255,37 +257,29 @@ def GetDicomGroups(directory, recursive=True, gui=True): | @@ -255,37 +257,29 @@ def GetDicomGroups(directory, recursive=True, gui=True): | ||
255 | data_dict['invesalius'] = {'orientation_label' : GetImageOrientationLabel(filename)} | 257 | data_dict['invesalius'] = {'orientation_label' : GetImageOrientationLabel(filename)} |
256 | 258 | ||
257 | # ------------------------------------------------------------- | 259 | # ------------------------------------------------------------- |
258 | - | ||
259 | - dict_file[os.path.abspath(filename)] = data_dict | 260 | + filepath = os.path.abspath(filename) |
261 | + dict_file[filepath] = data_dict | ||
262 | + | ||
263 | + if (data_dict['0002']['0002'] != "1.2.840.10008.1.3.10"): #DICOMDIR | ||
264 | + parser = dicom.Parser() | ||
265 | + parser.SetDataImage(dict_file[filepath], filepath) | ||
266 | + | ||
267 | + dcm = dicom.Dicom() | ||
268 | + dcm.SetParser(parser) | ||
269 | + grouper.AddFile(dcm) | ||
260 | 270 | ||
261 | - main_dict = dict( | ||
262 | - data = dict_file, | ||
263 | - labels = tag_labels) | 271 | + |
272 | + #------- to test ------------------------------------- | ||
273 | + #main_dict = dict( | ||
274 | + # data = dict_file, | ||
275 | + # labels = tag_labels) | ||
264 | 276 | ||
265 | #plistlib.writePlist(main_dict, ".//teste.plist") | 277 | #plistlib.writePlist(main_dict, ".//teste.plist") |
266 | - | ||
267 | - images = main_dict['data'] | ||
268 | - grouper = dicom_grouper.DicomPatientGrouper() | ||
269 | - | ||
270 | - for x in images.keys(): | ||
271 | - data_image = images[x] | ||
272 | - | ||
273 | - if (data_image['0002']['0002'] != "1.2.840.10008.1.3.10"): #DICOMDIR | ||
274 | - parser = dicom.Parser() | ||
275 | - parser.SetDataImage(data_image, x) | ||
276 | - | ||
277 | - dcm = dicom.Dicom() | ||
278 | - dcm.SetParser(parser) | ||
279 | - grouper.AddFile(dcm) | ||
280 | 278 | ||
281 | grouper.Update() | 279 | grouper.Update() |
282 | 280 | ||
283 | - | ||
284 | - | ||
285 | return grouper.GetPatientsGroups() | 281 | return grouper.GetPatientsGroups() |
286 | - #print "_____________________________________" | ||
287 | - #print dirpath | ||
288 | - #nfiles += len(filenames) | 282 | + |
289 | else: | 283 | else: |
290 | pass | 284 | pass |
291 | #dirpath, dirnames, filenames = os.walk(directory) | 285 | #dirpath, dirnames, filenames = os.walk(directory) |