Skip to content

Inconsistent writing of Metadata. Loading + Saving results in different metadata. #6136

Closed
@phcerdan

Description

@phcerdan

Describe the bug
Using SaveImage after LoadImage results in image saved with different metadata.

To Reproduce
Steps to reproduce the behavior:

    original2 = LoadImage(image_only=True)(original_file)
    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)(original2)

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:
image

The result after loading + saving with the above code:
image

Environment

Ensuring you use the relevant python executable, please paste the output of:

python -c 'import monai; monai.config.print_debug_info()'
MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False
MONAI rev id: a2ec3752f54bfc3b40e7952234fbeb5452ed63e3

Additional context
I have tested using itk:

original_itk = itk.imread(original_file)
itk.imwrite(original_itk, output_folder + "/monai_modified_meta/original_after_itk_save.nrrd")

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).

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions