Add missing channel_wise parameter to RandScaleIntensityFixedMean by engmohamedsalah · Pull Request #8741 · Project-MONAI/MONAI · GitHub
Skip to content

Add missing channel_wise parameter to RandScaleIntensityFixedMean#8741

Merged
ericspod merged 12 commits into
Project-MONAI:devfrom
engmohamedsalah:fix/add-channel-wise-randscaleintensityfixedmean-8363
Mar 29, 2026
Merged

Add missing channel_wise parameter to RandScaleIntensityFixedMean#8741
ericspod merged 12 commits into
Project-MONAI:devfrom
engmohamedsalah:fix/add-channel-wise-randscaleintensityfixedmean-8363

Conversation

@engmohamedsalah

Copy link
Copy Markdown
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

@coderabbitai

coderabbitai Bot commented Feb 14, 2026

Copy link
Copy Markdown
Contributor

@engmohamedsalah engmohamedsalah force-pushed the fix/add-channel-wise-randscaleintensityfixedmean-8363 branch from 738a3f9 to da88dbe Compare February 23, 2026 14:22
…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>
@engmohamedsalah engmohamedsalah force-pushed the fix/add-channel-wise-randscaleintensityfixedmean-8363 branch from da88dbe to f996a93 Compare February 23, 2026 15:43

@ericspod ericspod left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @engmohamedsalah I made a few comments below but it otherwise looks good to me with a few changes. Thanks!

Comment thread monai/transforms/intensity/array.py Outdated
Comment thread monai/transforms/intensity/array.py Outdated
Comment thread monai/transforms/intensity/array.py
Comment thread monai/transforms/intensity/dictionary.py Outdated
… 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>
@engmohamedsalah

Copy link
Copy Markdown
Contributor Author

@ericspod ericspod enabled auto-merge (squash) March 29, 2026 19:01
@ericspod ericspod merged commit 199084a into Project-MONAI:dev Mar 29, 2026
26 checks passed
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>
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

2 participants