Skip to content

Fix ClipIntensityPercentiles metadata accumulation#9003

Open
engmohamedsalah wants to merge 1 commit into
Project-MONAI:devfrom
engmohamedsalah:fix-clip-intensity-percentiles-metadata
Open

Fix ClipIntensityPercentiles metadata accumulation#9003
engmohamedsalah wants to merge 1 commit into
Project-MONAI:devfrom
engmohamedsalah:fix-clip-intensity-percentiles-metadata

Conversation

@engmohamedsalah

Copy link
Copy Markdown
Contributor

Description

ClipIntensityPercentiles stored returned clipping values on the transform instance. Reusing the same transform therefore accumulated values from earlier calls and also mutated the metadata of earlier outputs.

This change keeps the clipping-value accumulator local to each __call__. Each result now receives only its own clipping values, and later calls cannot change metadata already returned to a caller.

Regression tests cover repeated channel-wise and non-channel-wise calls.

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.

Testing

  • python -m unittest tests.transforms.test_clip_intensity_percentiles tests.transforms.test_clip_intensity_percentilesd — 96 tests passed
  • python -m ruff check monai/transforms/intensity/array.py tests/transforms/test_clip_intensity_percentiles.py
  • python -m black --check monai/transforms/intensity/array.py tests/transforms/test_clip_intensity_percentiles.py

Signed-off-by: Mohamed Abdeltawab <mohamed.abdeltawab@integrant.com>
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

ClipIntensityPercentiles now collects clipping percentile pairs in a local list for each invocation, passes that list through both clipping paths, and stores it in image metadata when enabled. New tests cover repeated channel-wise and non-channel-wise calls to ensure metadata does not leak between invocations.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately names the main fix to ClipIntensityPercentiles metadata handling.
Description check ✅ Passed The description covers the change, impact, change type, and testing, matching the template well.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@monai/transforms/intensity/array.py`:
- Around line 1177-1178: Update the clipping_values assignment in the transform
logic to verify that img has a meta attribute before accessing it, while
preserving the existing clipping_values non-None condition and metadata
assignment when available.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 172b6c36-87cd-48a5-82ae-6a2627769c24

📥 Commits

Reviewing files that changed from the base of the PR and between 5da2472 and 7904d66.

📒 Files selected for processing (2)
  • monai/transforms/intensity/array.py
  • tests/transforms/test_clip_intensity_percentiles.py

Comment thread monai/transforms/intensity/array.py
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.

1 participant