Commit 852d34153b682b5b505b32ed53e14721ca96e67a

Authored by Paulo Henrique Junqueira Amorim
1 parent 7ed6d001

FIX: Bug in the FixProblem1 error getting z spacing

Showing 1 changed file with 17 additions and 10 deletions   Show diff stats
invesalius/reader/dicom_grouper.py
@@ -114,7 +114,7 @@ class PatientGroup: @@ -114,7 +114,7 @@ class PatientGroup:
114 # (dicom.patient.name, dicom.patient.id) 114 # (dicom.patient.name, dicom.patient.id)
115 self.key = () 115 self.key = ()
116 self.groups_dict = {} # group_key: DicomGroup 116 self.groups_dict = {} # group_key: DicomGroup
117 - self.slices = 0 117 + self.nslices = 0
118 118
119 def AddFile(self, dicom, index=0): 119 def AddFile(self, dicom, index=0):
120 # Given general DICOM information, we group slices according 120 # Given general DICOM information, we group slices according
@@ -130,7 +130,7 @@ class PatientGroup: @@ -130,7 +130,7 @@ class PatientGroup:
130 dicom.acquisition.serie_number, 130 dicom.acquisition.serie_number,
131 dicom.image.orientation_label, 131 dicom.image.orientation_label,
132 index) # This will be used to deal with Problem 2 132 index) # This will be used to deal with Problem 2
133 - 133 + self.nslices += 1
134 # Does this group exist? Best case ;) 134 # Does this group exist? Best case ;)
135 if group_key not in self.groups_dict.keys(): 135 if group_key not in self.groups_dict.keys():
136 group = DicomGroup() 136 group = DicomGroup()
@@ -144,9 +144,10 @@ class PatientGroup: @@ -144,9 +144,10 @@ class PatientGroup:
144 # If we're here, then Problem 2 occured 144 # If we're here, then Problem 2 occured
145 # TODO: Optimize recursion 145 # TODO: Optimize recursion
146 self.AddFile(dicom, index+1) 146 self.AddFile(dicom, index+1)
147 -  
148 - group.GetSpacing()  
149 - 147 +
  148 + #Getting the spacing in the Z axis
  149 + group.GetSpacing()
  150 +
150 def Update(self): 151 def Update(self):
151 # Ideally, AddFile would be sufficient for splitting DICOM 152 # Ideally, AddFile would be sufficient for splitting DICOM
152 # files into groups (series). However, this does not work for 153 # files into groups (series). However, this does not work for
@@ -157,14 +158,14 @@ class PatientGroup: @@ -157,14 +158,14 @@ class PatientGroup:
157 158
158 # Check if Problem 1 occurs (n groups with 1 slice each) 159 # Check if Problem 1 occurs (n groups with 1 slice each)
159 is_there_problem_1 = False 160 is_there_problem_1 = False
160 - if (self.ndicom == len(self.groups_dicom)) and\  
161 - (self.ndicom > 1): 161 + if (self.nslices == len(self.groups_dict)) and\
  162 + (self.nslices > 1):
162 is_there_problem_1 = True 163 is_there_problem_1 = True
163 164
164 # Fix Problem 1 165 # Fix Problem 1
165 if is_there_problem_1: 166 if is_there_problem_1:
166 self.groups_dict = self.FixProblem1(self.groups_dict) 167 self.groups_dict = self.FixProblem1(self.groups_dict)
167 - 168 +
168 def GetGroups(self): 169 def GetGroups(self):
169 return self.groups_dict.values() 170 return self.groups_dict.values()
170 171
@@ -192,8 +193,9 @@ class PatientGroup: @@ -192,8 +193,9 @@ class PatientGroup:
192 # 1st STEP: RE-GROUP 193 # 1st STEP: RE-GROUP
193 for group_key in dict: 194 for group_key in dict:
194 # values used as key of the new dictionary 195 # values used as key of the new dictionary
195 - orientation = dict[group_key].image.orientation_label  
196 - study_id = dict[group_key].acquisition.id_study 196 + dicom = dict[group_key].GetList()[0]
  197 + orientation = dicom.image.orientation_label
  198 + study_id = dicom.acquisition.id_study
197 # if axial, coronal or sagittal 199 # if axial, coronal or sagittal
198 if orientation in ORIENT_MAP: 200 if orientation in ORIENT_MAP:
199 group_key_s = (orientation, study_id) 201 group_key_s = (orientation, study_id)
@@ -234,11 +236,16 @@ class PatientGroup: @@ -234,11 +236,16 @@ class PatientGroup:
234 group = DicomGroup() 236 group = DicomGroup()
235 group.AddSlice(current) 237 group.AddSlice(current)
236 dict_final[group_counter] = group 238 dict_final[group_counter] = group
  239 + #Getting the spacing in the Z axis
  240 + group.GetSpacing()
237 else: 241 else:
238 group_counter +=1 242 group_counter +=1
239 group = DicomGroup() 243 group = DicomGroup()
240 group.AddSlice(current) 244 group.AddSlice(current)
241 dict_final[group_counter] = group 245 dict_final[group_counter] = group
  246 + #Getting the spacing in the Z axis
  247 + group.GetSpacing()
  248 +
242 249
243 return dict_final 250 return dict_final
244 251