Skip to content

Spacing transform does not update pixdim #6832

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

Closed
KumoLiu opened this issue Aug 7, 2023 Discussed in #6831 · 3 comments
Closed

Spacing transform does not update pixdim #6832

KumoLiu opened this issue Aug 7, 2023 Discussed in #6831 · 3 comments
Labels
bug Something isn't working

Comments

@KumoLiu
Copy link
Contributor

KumoLiu commented Aug 7, 2023

Discussed in #6831

Originally posted by agaldran August 7, 2023
Hello,

Sorry about the naive question, I am trying to wrap my head around transforms and meta_dicts. Right now I have the following operations:

import monai.transforms as t

data_dict = {'image': 'data/ct/images/.whatever.nii.gz'}
loader = t.LoadImaged(keys=('image'), image_only=False)
loaded_data_dict = loader(data_dict)
print(loaded_data_dict['image'].shape, loaded_data_dict['image_meta_dict']['pixdim'][1:4])

which returns a shape and voxel sizes of [281, 313, 182] and (0.50,0.50,0.75) respectively. Now, if I run:

spacing = t.Spacingd(keys=['image'], pixdim=(0.50, 0.50, 1.5), mode=('bilinear')) 
spaced_data_dict = spacing(loaded_data_dict)
print(spaced_data_dict['image'].shape, spaced_data_dict['image_meta_dict']['pixdim'][1:4])

I am expecting to see approx half the voxels in the Z direction, as the original spacing was 0.75 and I am asking for twice that spacing. For the other directions, nothing should be changed^* . This is what I get:

[281, 313, 92], (0.50,0.50,0.75)

So, although the number of voxels are as expected, the spacing remains the same. I cannot find any other key in the meta data dictionary that tells me what is the current spacing for this volume. Am I doing something wrong here?

@KumoLiu KumoLiu added the bug Something isn't working label Aug 7, 2023
@wyli
Copy link
Contributor

wyli commented Aug 7, 2023

yes, the image's original 'pixdim' is not modified, the current pixdim is a property: spaced_data_dict["image"].pixdim

@KumoLiu
Copy link
Contributor Author

KumoLiu commented Aug 7, 2023

yes, the image's original 'pixdim' is not modified, the current pixdim is a property: spaced_data_dict["image"].pixdim

Does it mean we don't need to modify it or we may enhance it in the future?

@wyli
Copy link
Contributor

wyli commented Aug 8, 2023

We don't have a good reason to modify it at the moment, a single source of truth for the original and current pixdim seems to be consistent and easy to maintain..

@KumoLiu KumoLiu closed this as completed Aug 8, 2023
slicepaste added a commit to slicepaste/MONAI that referenced this issue Dec 23, 2024
According to the issue, this PR addresses on the meta dictionary `data['pixdim']` of NIfTI images does not update after applying the `spacing` or `spacingd`.
To align with `affine`, we update `data['pixdim']` and keep the original metainfo in `data['original_pixdim']`.
Additionally, this PR also update the metainfo `key_{meta_key_postfix}['pixdim']` in NIfTI images, consistent with `spaced_data_dict['image_meta_dict']['pixdim']` in issue Project-MONAI#6832.

Signed-off-by: Wei_Chuan, Chiang <[email protected]>
Co-authored-by: einsyang723 <[email protected]>
Co-authored-by: IamTingTing <[email protected]>
slicepaste added a commit to slicepaste/MONAI that referenced this issue Mar 6, 2025
According to the issue, this PR addresses on the meta dictionary `data['pixdim']` of NIfTI images does not update after applying the `spacing` or `spacingd`.
To align with `affine`, we update `data['pixdim']` and keep the original metainfo in `data['original_pixdim']`.
Additionally, this PR also update the metainfo `key_{meta_key_postfix}['pixdim']` in NIfTI images, consistent with `spaced_data_dict['image_meta_dict']['pixdim']` in issue Project-MONAI#6832.

Signed-off-by: Wei_Chuan, Chiang <[email protected]>
Co-authored-by: einsyang723 <[email protected]>
Co-authored-by: IamTingTing <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants