Commit 69671ddcbdab5850cb3442afcb638b4577a3e89a
1 parent
45e979a1
Exists in
master
Checking if a tag element has undefined length
Showing
1 changed file
with
36 additions
and
37 deletions
Show diff stats
invesalius/reader/dicom_reader.py
| ... | ... | @@ -118,11 +118,11 @@ class LoadDicom: |
| 118 | 118 | # Retrieve header |
| 119 | 119 | header = file.GetHeader() |
| 120 | 120 | stf = gdcm.StringFilter() |
| 121 | + stf.SetFile(file) | |
| 121 | 122 | |
| 122 | 123 | field_dict = {} |
| 123 | 124 | data_dict = {} |
| 124 | 125 | |
| 125 | - | |
| 126 | 126 | tag = gdcm.Tag(0x0008, 0x0005) |
| 127 | 127 | ds = reader.GetFile().GetDataSet() |
| 128 | 128 | if ds.FindDataElement(tag): |
| ... | ... | @@ -138,53 +138,52 @@ class LoadDicom: |
| 138 | 138 | else: |
| 139 | 139 | encoding = "ISO_IR 100" |
| 140 | 140 | |
| 141 | - | |
| 142 | 141 | # Iterate through the Header |
| 143 | 142 | iterator = header.GetDES().begin() |
| 144 | 143 | while (not iterator.equal(header.GetDES().end())): |
| 145 | 144 | dataElement = iterator.next() |
| 146 | - stf.SetFile(file) | |
| 147 | - tag = dataElement.GetTag() | |
| 148 | - data = stf.ToStringPair(tag) | |
| 149 | - stag = tag.PrintAsPipeSeparatedString() | |
| 150 | - | |
| 151 | - group = str(tag.GetGroup()) | |
| 152 | - field = str(tag.GetElement()) | |
| 145 | + if not dataElement.IsUndefinedLength(): | |
| 146 | + tag = dataElement.GetTag() | |
| 147 | + data = stf.ToStringPair(tag) | |
| 148 | + stag = tag.PrintAsPipeSeparatedString() | |
| 153 | 149 | |
| 154 | - tag_labels[stag] = data[0] | |
| 155 | - | |
| 156 | - if not group in data_dict.keys(): | |
| 157 | - data_dict[group] = {} | |
| 150 | + group = str(tag.GetGroup()) | |
| 151 | + field = str(tag.GetElement()) | |
| 158 | 152 | |
| 159 | - if not(utils.VerifyInvalidPListCharacter(data[1])): | |
| 160 | - data_dict[group][field] = data[1].decode(encoding) | |
| 161 | - else: | |
| 162 | - data_dict[group][field] = "Invalid Character" | |
| 153 | + tag_labels[stag] = data[0] | |
| 154 | + | |
| 155 | + if not group in data_dict.keys(): | |
| 156 | + data_dict[group] = {} | |
| 157 | + | |
| 158 | + if not(utils.VerifyInvalidPListCharacter(data[1])): | |
| 159 | + data_dict[group][field] = data[1].decode(encoding) | |
| 160 | + else: | |
| 161 | + data_dict[group][field] = "Invalid Character" | |
| 163 | 162 | |
| 164 | - | |
| 165 | 163 | # Iterate through the Data set |
| 166 | 164 | iterator = dataSet.GetDES().begin() |
| 167 | 165 | while (not iterator.equal(dataSet.GetDES().end())): |
| 168 | 166 | dataElement = iterator.next() |
| 169 | - | |
| 170 | - stf.SetFile(file) | |
| 171 | - tag = dataElement.GetTag() | |
| 172 | - data = stf.ToStringPair(tag) | |
| 173 | - stag = tag.PrintAsPipeSeparatedString() | |
| 174 | - | |
| 175 | - group = str(tag.GetGroup()) | |
| 176 | - field = str(tag.GetElement()) | |
| 177 | - | |
| 178 | - tag_labels[stag] = data[0] | |
| 179 | - | |
| 180 | - if not group in data_dict.keys(): | |
| 181 | - data_dict[group] = {} | |
| 182 | - | |
| 183 | - if not(utils.VerifyInvalidPListCharacter(data[1])): | |
| 184 | - data_dict[group][field] = data[1].decode(encoding, 'replace') | |
| 185 | - else: | |
| 186 | - data_dict[group][field] = "Invalid Character" | |
| 187 | - | |
| 167 | + if not dataElement.IsUndefinedLength(): | |
| 168 | + tag = dataElement.GetTag() | |
| 169 | + # if (tag.GetGroup() == 0x0009 and tag.GetElement() == 0x10e3) \ | |
| 170 | + # or (tag.GetGroup() == 0x0043 and tag.GetElement() == 0x1027): | |
| 171 | + # continue | |
| 172 | + data = stf.ToStringPair(tag) | |
| 173 | + stag = tag.PrintAsPipeSeparatedString() | |
| 174 | + | |
| 175 | + group = str(tag.GetGroup()) | |
| 176 | + field = str(tag.GetElement()) | |
| 177 | + | |
| 178 | + tag_labels[stag] = data[0] | |
| 179 | + | |
| 180 | + if not group in data_dict.keys(): | |
| 181 | + data_dict[group] = {} | |
| 182 | + | |
| 183 | + if not(utils.VerifyInvalidPListCharacter(data[1])): | |
| 184 | + data_dict[group][field] = data[1].decode(encoding, 'replace') | |
| 185 | + else: | |
| 186 | + data_dict[group][field] = "Invalid Character" | |
| 188 | 187 | |
| 189 | 188 | |
| 190 | 189 | # -------------- To Create DICOM Thumbnail ----------- | ... | ... |