Skip to content

Update ['pixdim'] after Spacing transform in meta dict. #8269

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

Open
wants to merge 34 commits into
base: dev
Choose a base branch
from

Conversation

slicepaste
Copy link
Contributor

@slicepaste slicepaste commented Dec 23, 2024

Fixes #6840

Description

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 #6832.

Types of changes

  • 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).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

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 <jamesis1356@gmail.com>
Co-authored-by: einsyang723 <tina910723@gmail.com>
Co-authored-by: IamTingTing <6121smile@gmail.com>
@slicepaste slicepaste changed the title Fixes #6840 Update ['pixdim'] after Spacing transform in meta dict. Dec 23, 2024
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Copy link
Contributor

@KumoLiu KumoLiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! Leave several comments inline.

@atbenmurray
Copy link
Contributor

atbenmurray commented Jan 17, 2025

Hi folks. I had a look through the code and the PR, but I need to do a deeper evaluation of how this intersects with lazy resampling and the consistency of behaviour between MetaTensor and _meta_dict modes

@KumoLiu KumoLiu requested a review from ericspod January 17, 2025 15:28
@atbenmurray
Copy link
Contributor

In the middle of extending test scenarios. Please bear with me.

@slicepaste
Copy link
Contributor Author

@einsyang723 @IamTingTing The current PR is not our final version, and it has remained unchanged for a while.
We should continue working on this issue and update the final version ASAP so we can move forward with this PR.
Let me know if you need any help. Thanks!

slicepaste and others added 11 commits February 17, 2025 16:22
Previously, a method was defined in `meta_tensor`, and using `data_array.clone()` introduced additional costs.
After reevaluating the code, modifying the `TraceableTransform.track_transform_meta()` method executed by `SpatialResample` makes it much cleaner and more maintainable.

Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Co-authored-by: einsyang723 <tina910723@gmail.com>
Co-authored-by: IamTingTing  <6121smile@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Co-authored-by: einsyang723 <tina910723@gmail.com>
Co-authored-by: IamTingTing  <6121smile@gmail.com>
Previously, a method was defined in `meta_tensor`, and using `data_array.clone()` introduced additional costs.
After reevaluating the code, modifying the `TraceableTransform.track_transform_meta()` method executed by `SpatialResample` makes it much cleaner and more maintainable.

Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Co-authored-by: einsyang723 <tina910723@gmail.com>
Co-authored-by: IamTingTing  <6121smile@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Co-authored-by: einsyang723 <tina910723@gmail.com>
Co-authored-by: IamTingTing  <6121smile@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Co-authored-by: einsyang723 <tina910723@gmail.com>
Co-authored-by: IamTingTing  <6121smile@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Co-authored-by: einsyang723 <tina910723@gmail.com>
Co-authored-by: IamTingTing  <6121smile@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Co-authored-by: einsyang723 <tina910723@gmail.com>
Co-authored-by: IamTingTing  <6121smile@gmail.com>
@atbenmurray
Copy link
Contributor

Picking this up again. Will have a review for you all today.

slicepaste and others added 15 commits March 6, 2025 17:25
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 <jamesis1356@gmail.com>
Co-authored-by: einsyang723 <tina910723@gmail.com>
Co-authored-by: IamTingTing <6121smile@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Previously, a method was defined in `meta_tensor`, and using `data_array.clone()` introduced additional costs.
After reevaluating the code, modifying the `TraceableTransform.track_transform_meta()` method executed by `SpatialResample` makes it much cleaner and more maintainable.

Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Co-authored-by: einsyang723 <tina910723@gmail.com>
Co-authored-by: IamTingTing  <6121smile@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Co-authored-by: einsyang723 <tina910723@gmail.com>
Co-authored-by: IamTingTing  <6121smile@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Co-authored-by: einsyang723 <tina910723@gmail.com>
Co-authored-by: IamTingTing  <6121smile@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Co-authored-by: einsyang723 <tina910723@gmail.com>
Co-authored-by: IamTingTing  <6121smile@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Co-authored-by: einsyang723 <tina910723@gmail.com>
Co-authored-by: IamTingTing  <6121smile@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Co-authored-by: einsyang723 <tina910723@gmail.com>
Co-authored-by: IamTingTing  <6121smile@gmail.com>
Checking all dictionary keys that start with `{key}_` to support custom settings of `meta_keys` and `meta_key_postfix`.
This ensures that no matter how users configure the naming conventions in `LoadImaged`,
we can correctly synchronize metadata from the MetaTensor to the corresponding meta dictionary.

Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Co-authored-by: einsyang723 <tina910723@gmail.com>
Co-authored-by: IamTingTing  <6121smile@gmail.com>
Signed-off-by: Wei_Chuan, Chiang <jamesis1356@gmail.com>
Co-authored-by: einsyang723 <tina910723@gmail.com>
Co-authored-by: IamTingTing  <6121smile@gmail.com>
@atbenmurray
Copy link
Contributor

@einsyang723 @slicepaste @ericspod @KumoLiu @IamTingTing
Hi folks. Sorry it has been a while but I have a candidate PR #8411 that I think is important to address as a prerequisite to this PR. It is still in draft phase but take a look when you have a moment

Copy link
Contributor

@atbenmurray atbenmurray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change made in monai/transforms/spatial/dictionary.py means the issue that I raised is much less relevant now

@slicepaste
Copy link
Contributor Author

The change made in monai/transforms/spatial/dictionary.py means the issue that I raised is much less relevant now

@atbenmurray Thank you for the approval. Just to confirm our understanding — this PR can be merged first, and the remaining concerns regarding meta_keys, meta_key_postfix, and the additional metadata dictionary changes will be addressed in PR #8411 , right?

@atbenmurray
Copy link
Contributor

The change made in monai/transforms/spatial/dictionary.py means the issue that I raised is much less relevant now

@atbenmurray Thank you for the approval. Just to confirm our understanding — this PR can be merged first, and the remaining concerns regarding meta_keys, meta_key_postfix, and the additional metadata dictionary changes will be addressed in PR #8411 , right?

Exactly. Yes. This PR is decoupled from PR #8411 now.

@slicepaste
Copy link
Contributor Author

Exactly. Yes. This PR is decoupled from PR #8411 now.

Thanks for the confirmation. Looking forward to the merge!

Copy link
Member

@ericspod ericspod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think everything has been addressed here, @KumoLiu please trigger blossom and we'll integrate this soon. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modify pixdim to original_pixdim in meta dict
5 participants