Commit 586739ecae59f3604b831e67e7636d16fdbbfb16

Authored by Paulo Henrique Junqueira Amorim
1 parent 661fb4fe

ENH: Removed list of list from dicom_grouper

invesalius/reader/dicom_grouper.py
... ... @@ -282,32 +282,29 @@ class DicomGroups:
282 282 for x in xrange(size_tmp_list):
283 283  
284 284 tmp1 = tmp_list[x]
285   -
286   -
287 285 for m in xrange(len(tmp1.keys())):
288 286  
289 287 key = tmp1.keys()[m]
290 288 information = tmp1[key]
  289 +
291 290 new_key = (information.patient.name, information.image.orientation_label,
292 291 information.acquisition.serie_number)
293   -
294   -
  292 +
295 293 if (new_key in groups_dcm_.keys()):
296   - groups_dcm_[new_key][0].append(information)
  294 + groups_dcm_[new_key].append(information)
297 295 else:
298   - groups_dcm_[new_key] = [[information]]
  296 + groups_dcm_[new_key] = [information]
299 297  
300 298 #the number of previously existing number is
301 299 #greater or equal then the group keeps up,
302 300 #but maintains the same group of positions.
303   - if len(self.groups_dcm.keys()) > len(groups_dcm_.keys()):
304   - self.groups_dcm = groups_dcm_
  301 + #if len(self.groups_dcm.keys()) > len(groups_dcm_.keys()):
  302 + self.groups_dcm = groups_dcm_
305 303  
306   -
307 304 for j in xrange(len(self.groups_dcm.keys())):
308 305 key = self.groups_dcm.keys()[j]
309   - self.groups_dcm[key][0].sort(key=lambda x: x.image.number)
310   -
  306 + self.groups_dcm[key].sort(key=lambda x: x.image.number)
  307 +
311 308  
312 309 def __UpdateZSpacing(self):
313 310 """
... ... @@ -315,23 +312,27 @@ class DicomGroups:
315 312 """
316 313  
317 314 for x in xrange(len(self.groups_dcm.keys())):
318   -
  315 + print len(self.groups_dcm.keys())
  316 +
319 317 key = self.groups_dcm.keys()[x]
320 318 information = self.groups_dcm[key][0]
321   - if (len(self.groups_dcm[key][0]) > 1):
  319 + if (len(self.groups_dcm[key]) > 1):
322 320 #Catch a slice of middle and the next to find the spacing.
323   - center = len(self.groups_dcm[key][0])/2
  321 + center = len(self.groups_dcm[key])/2
324 322 if (center == 1):
325 323 center = 0
326 324  
327   - information = self.groups_dcm[key][0][center]
  325 + information = self.groups_dcm[key][center]
328 326 current_position = information.image.position
329 327  
330   - information = self.groups_dcm[key][0][center + 1]
  328 + information = self.groups_dcm[key][center + 1]
331 329 next_position = information.image.position
332 330  
333 331 try:
334   - image_orientation_label = self.groups_dcm.keys()[x][3]
  332 + information = self.groups_dcm[self.groups_dcm.keys()[x]][3]
  333 + image_orientation_label = information.image.orientation_label
  334 + print image_orientation_label
  335 +
335 336 except(IndexError):
336 337 image_orientation_label = None
337 338  
... ... @@ -347,6 +348,6 @@ class DicomGroups:
347 348 else:
348 349 spacing = None
349 350  
350   - for information in self.groups_dcm[key][0]:
  351 + for information in self.groups_dcm[key]:
351 352 if information.image.spacing:
352 353 information.image.spacing[2] = spacing
... ...
invesalius/reader/dicom_reader.py
... ... @@ -45,8 +45,8 @@ def LoadImages(dir_):
45 45 for x in xrange(len(groups.keys())):
46 46 key = groups.keys()[x]
47 47  
48   - for y in xrange(len(groups[key][0])):
49   - dicom = groups[key][0][y]
  48 + for y in xrange(len(groups[key])):
  49 + dicom = groups[key][y]
50 50 file = dicom.image.file
51 51 tmp_list.append(file)
52 52  
... ... @@ -59,8 +59,8 @@ def LoadImages(dir_):
59 59 return None
60 60  
61 61 file_list = []
62   - for x in xrange(len(groups[key][0])):
63   - dicom = groups[key][0][x]
  62 + for x in xrange(len(groups[key])):
  63 + dicom = groups[key][x]
64 64 file_list.append(dicom.image.file)
65 65  
66 66 files = file_list
... ...