Skip to content

StdShiftIntensity does redundant full-image mask + gather + scatter on the default nonzero=False path #8972

Closed

Description

@aymuos15

Describe the bug

StdShiftIntensity._stdshift (monai/transforms/intensity/array.py) always builds a full-image boolean mask, gathers every voxel through it, computes the std on that copy, and scatters back:

slices = (img != 0) if self.nonzero else ones(img.shape, dtype=bool)
if slices.any():
    offset = self.factor * std(img[slices])
    img[slices] = img[slices] + offset

On the default nonzero=False path (also the default for RandStdShiftIntensity), slices is all-True, so std(img[slices]) == std(img) and the scatter is just img + offset. The mask allocation, .any(), gather and scatter are extra.

Activity

  1. added a commit that references this issue on Jul 6, 2026
    229f519
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions