{{ message }}
Add missing channel_wise parameter to RandScaleIntensityFixedMean#8741
Merged
ericspod merged 12 commits intoMar 29, 2026
Conversation
Contributor
738a3f9 to
da88dbe
Compare
…oject-MONAI#8363) The channel_wise parameter was documented in the docstring but not actually accepted by RandScaleIntensityFixedMean or its dictionary variant. This adds the parameter with per-channel random factor generation and scaling, matching the existing pattern in RandScaleIntensity. Also fixes docstring indentation. Signed-off-by: Mohamed Salah <eng.mohamed.tawab@gmail.com>
da88dbe to
f996a93
Compare
ericspod
requested changes
Mar 1, 2026
ericspod
left a comment
Member
There was a problem hiding this comment.
Hi @engmohamedsalah I made a few comments below but it otherwise looks good to me with a few changes. Thanks!
… simplify loop - Move channel_wise parameter to end of argument list in both array and dictionary variants to preserve positional argument compatibility - Use R.uniform(size=) instead of list comprehension for per-channel factors - Simplify channel-wise __call__ using float() cast, torch.cat, and removing redundant [0] index - Reorder docstrings to match new argument order Signed-off-by: Mohamed Salah <eng.mohamed.tawab@gmail.com>
…nd cat - Add type: ignore[index] for self.factor[i] since mypy can't narrow the type in the channel_wise branch - Add type: ignore[arg-type] for scale_trans output appended to list - Type out list as list[torch.Tensor] to satisfy torch.cat signature - Follows same pattern as existing RandScaleIntensity (line 738-740) Signed-off-by: Mohamed Salah <eng.mohamed.tawab@gmail.com>
Contributor
Author
ericspod
approved these changes
Mar 29, 2026
Rusheel86
pushed a commit
to Rusheel86/MONAI
that referenced
this pull request
May 25, 2026
…oject-MONAI#8741) ## 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 Project-MONAI#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 - [x] All existing tests pass (no regressions) - [x] New `channel_wise` tests pass for both array and dictionary transforms - [x] Verified per-channel mean preservation with `fixed_mean=True` - [x] Verified `preserve_range` clipping works per channel --------- Signed-off-by: Mohamed Salah <eng.mohamed.tawab@gmail.com> Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
channel_wiseparameter toRandScaleIntensityFixedMeanandRandScaleIntensityFixedMeand, which was documented in docstrings but never implemented.channel_wise=True, a separate random scale factor is generated per channel, andpreserve_range/fixed_meanare applied per channel — following the existing pattern fromRandScaleIntensity.channel_wisein both array and dictionary transforms.Fixes #8363
Changes
monai/transforms/intensity/array.pychannel_wiseparameter toRandScaleIntensityFixedMean.__init__randomize()to generate per-channel factors whenchannel_wise=True__call__to apply per-channel scaling with individual random factorsmonai/transforms/intensity/dictionary.pychannel_wiseparameter toRandScaleIntensityFixedMeand.__init____call__to pass image data torandomize()(needed for channel count), following the pattern fromRandScaleIntensitydTests
test_channel_wiseandtest_channel_wise_preserve_rangetotest_rand_scale_intensity_fixed_mean.pytest_channel_wisetotest_rand_scale_intensity_fixed_meand.pyTest plan
channel_wisetests pass for both array and dictionary transformsfixed_mean=Truepreserve_rangeclipping works per channel