Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoadImage/SaveImage consistency with itk reader #2613

Closed
wyli opened this issue Jul 15, 2021 · 0 comments · Fixed by #2615
Closed

LoadImage/SaveImage consistency with itk reader #2613

wyli opened this issue Jul 15, 2021 · 0 comments · Fixed by #2615
Assignees
Labels
enhancement New feature or request

Comments

@wyli
Copy link
Contributor

wyli commented Jul 15, 2021

Describe the bug
Saving a Dicom image into Nifti, and load the nifti, we should get the same data representation.

To Reproduce

import itk

from monai.transforms import Compose, EnsureChannelFirstD, LoadImageD, SaveImageD

img_dir = "tests/testing_data/CT_DICOM"
data_dict = {"img": img_dir}
keys = data_dict.keys()
xforms = Compose(
    [
        LoadImageD(keys, reader="itkreader", pixel_type=itk.UC),
        EnsureChannelFirstD(keys),
    ]
)
img_dict = xforms(data_dict)  # load dicom with itk

save_xform = SaveImageD(keys, meta_keys="img_meta_dict", output_dir=".")
save_xform(img_dict)  # save to nifti

new_xforms = Compose(
    [
        LoadImageD(keys, reader="itkreader"),
        EnsureChannelFirstD(keys),
    ]
)
out = new_xforms({"img": "CT_DICOM/CT_DICOM_trans.nii.gz"})  # load nifti with itk
print(img_dict["img"].shape)
print(out["img"].shape)
print(img_dict["img_meta_dict"]["affine"])
print(out["img_meta_dict"]["affine"])
print(img_dict["img_meta_dict"]["spatial_shape"])
print(out["img_meta_dict"]["spatial_shape"])

inconsistent output:

(1, 4, 16, 16)
(1, 16, 16, 4)
[[   0.488281      0.            0.         -125.        ]
 [   0.            0.488281      0.         -128.100006  ]
 [   0.            0.           68.33333333  -99.480003  ]
 [   0.            0.            0.            1.        ]]
[[ -0.48828101   0.           0.         125.        ]
 [  0.          -0.48828101   0.         128.1000061 ]
 [  0.           0.          68.33333588 -99.48000336]
 [  0.           0.           0.           1.        ]]
[ 4 16 16]
[16 16  4]

this is an integration issue of nibabel writer <=> itk reader

@wyli wyli self-assigned this Jul 15, 2021
@Nic-Ma Nic-Ma added the enhancement New feature or request label Jul 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants