Commit 50f903c2731625fcb15222036f82c8e78918a90b
1 parent
70dfcbb8
Exists in
master
reading one slice dicom
Showing
2 changed files
with
14 additions
and
15 deletions
Show diff stats
invesalius/reader/dicom.py
@@ -140,7 +140,7 @@ class Parser(): | @@ -140,7 +140,7 @@ class Parser(): | ||
140 | 140 | ||
141 | def SetDataImage(self, data_image, filename, thumbnail_path): | 141 | def SetDataImage(self, data_image, filename, thumbnail_path): |
142 | self.data_image = data_image | 142 | self.data_image = data_image |
143 | - self.filename = self.filepath = filename | 143 | + self.filename = self.filepath = filename |
144 | self.thumbnail_path = thumbnail_path | 144 | self.thumbnail_path = thumbnail_path |
145 | 145 | ||
146 | def __format_time(self,value): | 146 | def __format_time(self,value): |
@@ -508,12 +508,15 @@ class Parser(): | @@ -508,12 +508,15 @@ class Parser(): | ||
508 | DICOM standard tag (0x0028, 0x0030) was used. | 508 | DICOM standard tag (0x0028, 0x0030) was used. |
509 | """ | 509 | """ |
510 | try: | 510 | try: |
511 | - data = self.data_image[str(0x0028)][str(0x0030)].replace(",", ".") | ||
512 | - except(KeyError): | 511 | + return self.data_image["spacing"][:2] |
512 | + except KeyError: | ||
513 | + try: | ||
514 | + data = self.data_image[str(0x0028)][str(0x0030)].replace(",", ".") | ||
515 | + except(KeyError): | ||
516 | + return "" | ||
517 | + if (data): | ||
518 | + return [float(value) for value in data.split('\\')] | ||
513 | return "" | 519 | return "" |
514 | - if (data): | ||
515 | - return [eval(value) for value in data.split('\\')] | ||
516 | - return "" | ||
517 | 520 | ||
518 | def GetPatientWeight(self): | 521 | def GetPatientWeight(self): |
519 | """ | 522 | """ |
@@ -1953,7 +1956,7 @@ class Image(object): | @@ -1953,7 +1956,7 @@ class Image(object): | ||
1953 | self.position = [1, 1, 1] | 1956 | self.position = [1, 1, 1] |
1954 | 1957 | ||
1955 | self.number = parser.GetImageNumber() | 1958 | self.number = parser.GetImageNumber() |
1956 | - self.spacing = spacing = parser.GetPixelSpacing() | 1959 | + self.spacing = list(parser.GetPixelSpacing()) |
1957 | self.orientation_label = parser.GetImageOrientationLabel() | 1960 | self.orientation_label = parser.GetImageOrientationLabel() |
1958 | self.file = parser.filename | 1961 | self.file = parser.filename |
1959 | self.time = parser.GetImageTime() | 1962 | self.time = parser.GetImageTime() |
@@ -1966,12 +1969,6 @@ class Image(object): | @@ -1966,12 +1969,6 @@ class Image(object): | ||
1966 | self.number_of_frames = parser.GetNumberOfFrames() | 1969 | self.number_of_frames = parser.GetNumberOfFrames() |
1967 | 1970 | ||
1968 | if (parser.GetImageThickness()): | 1971 | if (parser.GetImageThickness()): |
1969 | - try: | ||
1970 | - spacing.append(parser.GetImageThickness()) | ||
1971 | - except(AttributeError): | ||
1972 | - spacing = [1, 1, 1] | 1972 | + self.spacing.append(parser.GetImageThickness()) |
1973 | else: | 1973 | else: |
1974 | - try: | ||
1975 | - spacing.append(1.5) | ||
1976 | - except(AttributeError): | ||
1977 | - spacing = [1, 1, 1] | 1974 | + self.spacing.append(1.0) |
invesalius/reader/dicom_reader.py
@@ -132,6 +132,8 @@ class LoadDicom: | @@ -132,6 +132,8 @@ class LoadDicom: | ||
132 | 132 | ||
133 | tag = gdcm.Tag(0x0008, 0x0005) | 133 | tag = gdcm.Tag(0x0008, 0x0005) |
134 | ds = reader.GetFile().GetDataSet() | 134 | ds = reader.GetFile().GetDataSet() |
135 | + image_helper = gdcm.ImageHelper() | ||
136 | + data_dict['spacing'] = image_helper.GetSpacingValue(reader.GetFile()) | ||
135 | if ds.FindDataElement(tag): | 137 | if ds.FindDataElement(tag): |
136 | encoding_value = str(ds.GetDataElement(tag).GetValue()).split('\\')[0] | 138 | encoding_value = str(ds.GetDataElement(tag).GetValue()).split('\\')[0] |
137 | 139 |