Skip to content

Commit

Permalink
Merge pull request #14 from niaid/use_simpleitk_2_1
Browse files Browse the repository at this point in the history
Update to use SimpleITK 2.1
  • Loading branch information
blowekamp authored Jul 26, 2021
2 parents 4b23736 + d36f63f commit e3ba3a5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions rap_sitkcore/read_dcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def _read_dcm_pydicom(filename: Path) -> sitk.Image:
if tag in ds:
de = ds.data_element(tag)
if de.VR in ["CS", "UI"]:
img.SetMetaData(f"{de.tag.group:04x}|{de.tag.elem:04x}", de.value)
img[f"{de.tag.group:04x}|{de.tag.elem:04x}"] = de.value
elif de.VR == "DS":
img.SetMetaData(f"{de.tag.group:04x}|{de.tag.elem:04x}", convert_float_list_to_mv_ds(de.value))
img[f"{de.tag.group:04x}|{de.tag.elem:04x}"] = convert_float_list_to_mv_ds(de.value)
else:
raise ValueError(
f'"{filename}" has data element "{de.name}" non-conforming value representation "{de.VR}".'
Expand Down Expand Up @@ -121,14 +121,14 @@ def read_dcm(filename: Path) -> sitk.Image:
key_to_keep = [keyword_to_gdcm_tag(n) for n in _keyword_to_copy]
for k in old_keys:
if k not in key_to_keep:
img.EraseMetaData(k)
del img[k]
return img
elif img.GetNumberOfComponentsPerPixel() == 3:
out = srgb2gray(img)
# copy tags
for tag_name in _keyword_to_copy:
key = keyword_to_gdcm_tag(tag_name)
if img.HasMetaDataKey(key):
out.SetMetaData(key, img.GetMetaData(key))
if key in img:
out[key] = img[key]
return out
raise RuntimeError(f"Unsupported number of components: {img.GetNumberOfComponentsPerPixel()}")
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SimpleITK ==2.0.2
SimpleITK >=2.1.0, <2.2
numpy >=1.19, <=1.20
pydicom

Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_read_dcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_read_dcm1(test_file):

for tag in required_tags:
key = keyword_to_gdcm_tag(tag)
assert img.HasMetaDataKey(key)
assert key in img

for k in img.GetMetaDataKeys():
assert k in _white_listed_dicom_tags
Expand Down

0 comments on commit e3ba3a5

Please sign in to comment.