Skip to content

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions