Skip to content

Add missing channel_wise parameter to RandScaleIntensityFixedMean#8741

Open
engmohamedsalah wants to merge 3 commits intoProject-MONAI:devfrom
engmohamedsalah:fix/add-channel-wise-randscaleintensityfixedmean-8363
Open

Add missing channel_wise parameter to RandScaleIntensityFixedMean#8741
engmohamedsalah wants to merge 3 commits intoProject-MONAI:devfrom
engmohamedsalah:fix/add-channel-wise-randscaleintensityfixedmean-8363

Conversation

@engmohamedsalah
Copy link
Contributor

Summary

  • Adds the channel_wise parameter to RandScaleIntensityFixedMean and RandScaleIntensityFixedMeand, which was documented in docstrings but never implemented.
  • When channel_wise=True, a separate random scale factor is generated per channel, and preserve_range/fixed_mean are applied per channel — following the existing pattern from RandScaleIntensity.
  • Fixes docstring indentation for channel_wise in both array and dictionary transforms.

Fixes #8363

Changes

monai/transforms/intensity/array.py

  • Added channel_wise parameter to RandScaleIntensityFixedMean.__init__
  • Updated randomize() to generate per-channel factors when channel_wise=True
  • Updated __call__ to apply per-channel scaling with individual random factors

monai/transforms/intensity/dictionary.py

  • Added channel_wise parameter to RandScaleIntensityFixedMeand.__init__
  • Updated __call__ to pass image data to randomize() (needed for channel count), following the pattern from RandScaleIntensityd

Tests

  • Added test_channel_wise and test_channel_wise_preserve_range to test_rand_scale_intensity_fixed_mean.py
  • Added test_channel_wise to test_rand_scale_intensity_fixed_meand.py

Test plan

  • All existing tests pass (no regressions)
  • New channel_wise tests pass for both array and dictionary transforms
  • Verified per-channel mean preservation with fixed_mean=True
  • Verified preserve_range clipping works per channel

…oject-MONAI#8363)

The channel_wise option was documented in docstrings but not actually
implemented in RandScaleIntensityFixedMean and its dictionary variant
RandScaleIntensityFixedMeand. This adds the parameter following the
existing pattern from RandScaleIntensity, generating per-channel random
scale factors when channel_wise=True.

Fixes Project-MONAI#8363
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 14, 2026

📝 Walkthrough

Walkthrough

This PR adds channel_wise support to RandScaleIntensityFixedMean across both array and dictionary transform variants. The array transform introduces a channel_wise boolean parameter, passes it to the internal ScaleIntensityFixedMean scaler, updates randomization to generate per-channel factors when enabled, and extends __call__ to apply per-channel scaling via channel iteration and stacking. The dictionary wrapper propagates the parameter and adjusts __call__ to enforce consistent spatial shapes across keys. Tests validate both basic channel-wise scaling and behavior with preserve_range.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Additional notes

The changes directly address the missing channel_wise functionality documented but not implemented (per the linked issue). The implementation maintains backward compatibility by defaulting channel_wise to False. Per-channel factor generation and the conditional branching in __call__ require careful attention to verify correctness of channel iteration, stacking, and type conversions.

🚥 Pre-merge checks | ✅ 5 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title accurately describes the main change: adding the missing channel_wise parameter to RandScaleIntensityFixedMean.
Description check ✅ Passed Description covers all required sections: summary, changes per file, tests added, and test plan with verification status.
Linked Issues check ✅ Passed PR fully implements the missing channel_wise parameter with per-channel scaling, preserve_range, and fixed_mean support, matching issue #8363 requirements.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing channel_wise support in RandScaleIntensityFixedMean/Meand and fixing docstring indentation as specified in issue #8363.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into dev

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
monai/transforms/intensity/array.py (1)

661-675: Per-channel ScaleIntensityFixedMean is instantiated on every call — consider reuse.

A new ScaleIntensityFixedMean is allocated per channel per invocation. This matches the RandScaleIntensity pattern (line 738), so it's consistent with the codebase. However, you could avoid repeated object creation by reusing self.scaler with per-channel factor overrides.

Also, self.scaler (constructed with channel_wise=True in __init__) is effectively dead code when channel_wise=True at runtime, since this branch always takes over.

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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 and usage tips.

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.

channel_wise option missing in transforms.RandScaleIntensityFixedMean

1 participant

Comments