-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Inconsistent writing of Metadata. Loading + Saving results in different metadata. #6136
Comments
thanks for reporting, I think there's a separate bug for the default image writing, will look into it soon. |
Thanks @wyli. |
yes, I also tried that, currently the usage is save = SaveImage(
output_dir=output_folder + "/monai_modified_meta",
output_ext=".nrrd",
writer="ITKWriter",
resample=False,
separate_folder=False,
squeeze_end_dims=False,
output_dtype=itk.SI,
)
save.set_options(init_kwargs={"affine_lps_to_ras": False})
save(original2) but this logic doesn't look right at the moment... MONAI/monai/data/image_writer.py Lines 501 to 502 in a8302ec
(another workaround is to set |
I find another bug when taking a look at this issue. MONAI/monai/data/image_reader.py Line 687 in 678b512
|
I would recommend to have only one source of truth for geometrical metadata (Origin, Spacing, Orientation), and that to be the |
Fixes #6136 fixes #6146 ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [x] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [x] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [x] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: Wenqi Li <wenqil@nvidia.com>
Describe the bug
Using SaveImage after LoadImage results in image saved with different metadata.
To Reproduce
Steps to reproduce the behavior:
Where
original_file
points to the attached image (a dcm 2D slice):CT.X.1.2.276.0.7230010.3.1.4.0.6.1667732449.1809819.zip
Expected behavior
The metadata should be the same of the original image after save.
Screenshots
The original dcm loaded in Slicer:
The result after loading + saving with the above code:
Environment
Ensuring you use the relevant python executable, please paste the output of:
Additional context
I have tested using
itk
:and the metadata is conserved (afer opening it in Slicer).
There must be some internal Monai logic messing this up.
The data is a bit odd, but correct, the spacing is negative. ITK corrects this at the moment of reading, flipping the sign in the direction matrix for those indices with negative spacing (and flipping the signs in spacing).
The text was updated successfully, but these errors were encountered: