Commit 852d34153b682b5b505b32ed53e14721ca96e67a
1 parent
7ed6d001
Exists in
master
and in
68 other branches
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 | 114 | # (dicom.patient.name, dicom.patient.id) |
115 | 115 | self.key = () |
116 | 116 | self.groups_dict = {} # group_key: DicomGroup |
117 | - self.slices = 0 | |
117 | + self.nslices = 0 | |
118 | 118 | |
119 | 119 | def AddFile(self, dicom, index=0): |
120 | 120 | # Given general DICOM information, we group slices according |
... | ... | @@ -130,7 +130,7 @@ class PatientGroup: |
130 | 130 | dicom.acquisition.serie_number, |
131 | 131 | dicom.image.orientation_label, |
132 | 132 | index) # This will be used to deal with Problem 2 |
133 | - | |
133 | + self.nslices += 1 | |
134 | 134 | # Does this group exist? Best case ;) |
135 | 135 | if group_key not in self.groups_dict.keys(): |
136 | 136 | group = DicomGroup() |
... | ... | @@ -144,9 +144,10 @@ class PatientGroup: |
144 | 144 | # If we're here, then Problem 2 occured |
145 | 145 | # TODO: Optimize recursion |
146 | 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 | 151 | def Update(self): |
151 | 152 | # Ideally, AddFile would be sufficient for splitting DICOM |
152 | 153 | # files into groups (series). However, this does not work for |
... | ... | @@ -157,14 +158,14 @@ class PatientGroup: |
157 | 158 | |
158 | 159 | # Check if Problem 1 occurs (n groups with 1 slice each) |
159 | 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 | 163 | is_there_problem_1 = True |
163 | 164 | |
164 | 165 | # Fix Problem 1 |
165 | 166 | if is_there_problem_1: |
166 | 167 | self.groups_dict = self.FixProblem1(self.groups_dict) |
167 | - | |
168 | + | |
168 | 169 | def GetGroups(self): |
169 | 170 | return self.groups_dict.values() |
170 | 171 | |
... | ... | @@ -192,8 +193,9 @@ class PatientGroup: |
192 | 193 | # 1st STEP: RE-GROUP |
193 | 194 | for group_key in dict: |
194 | 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 | 199 | # if axial, coronal or sagittal |
198 | 200 | if orientation in ORIENT_MAP: |
199 | 201 | group_key_s = (orientation, study_id) |
... | ... | @@ -234,11 +236,16 @@ class PatientGroup: |
234 | 236 | group = DicomGroup() |
235 | 237 | group.AddSlice(current) |
236 | 238 | dict_final[group_counter] = group |
239 | + #Getting the spacing in the Z axis | |
240 | + group.GetSpacing() | |
237 | 241 | else: |
238 | 242 | group_counter +=1 |
239 | 243 | group = DicomGroup() |
240 | 244 | group.AddSlice(current) |
241 | 245 | dict_final[group_counter] = group |
246 | + #Getting the spacing in the Z axis | |
247 | + group.GetSpacing() | |
248 | + | |
242 | 249 | |
243 | 250 | return dict_final |
244 | 251 | ... | ... |