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

8267 fix normalize intensity #8286

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

Conversation

advcu987
Copy link

@advcu987 advcu987 commented Jan 8, 2025

Fixes #8267 .

Description

Fix channel-wise intensity normalization for integer type inputs.

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.

    Fix channel-wise intensity normalization for integer type inputs.

    Signed-off-by: Adrian Voicu <[email protected]>
    Fix channel-wise intensity normalization for integer type inputs.

    Signed-off-by: Adrian Voicu <[email protected]>
I, advcu987 <[email protected]>, hereby add my Signed-off-by to this commit: b55a02e
I, advcu987 <[email protected]>, hereby add my Signed-off-by to this commit: 28a0df1
I, advcu987 <[email protected]>, hereby add my Signed-off-by to this commit: bdb3604

Signed-off-by: advcu987 <[email protected]>
@@ -907,6 +907,8 @@ def __call__(self, img: NdarrayOrTensor) -> NdarrayOrTensor:
if self.divisor is not None and len(self.divisor) != len(img):
raise ValueError(f"img has {len(img)} channels, but divisor has {len(self.divisor)} components.")

img, *_ = convert_data_type(img, dtype=torch.float32)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the fix. Seems we can remove the convert out side of the self._normalize to avoid convert multiple times here.

Copy link
Member

Choose a reason for hiding this comment

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

Should we also check that the dtype of img isn't float16/float32/float64 and only do the conversion in that case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it would be a little more rigorous. Although in the non channel-wise version, we do the conversion directly. But yes if we could do the check, would be better.

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.

monai.transforms.intensity.array.NormalizeIntensity bug when __call__ with channel_wise=True
3 participants