MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / ShiftIntensity

Class ShiftIntensity

monai/transforms/intensity/array.py:232–258  ·  view source on GitHub ↗

Shift intensity uniformly for the entire image with specified `offset`. Args: offset: offset value to shift the intensity of image. safe: if `True`, then do safe dtype convert when intensity overflow. default to `False`. E.g., `[256, -12]` -> `[array(0), array(2

Source from the content-addressed store, hash-verified

230
231
232class ShiftIntensity(Transform):
233 """
234 Shift intensity uniformly for the entire image with specified `offset`.
235
236 Args:
237 offset: offset value to shift the intensity of image.
238 safe: if `True`, then do safe dtype convert when intensity overflow. default to `False`.
239 E.g., `[256, -12]` -> `[array(0), array(244)]`. If `True`, then `[256, -12]` -> `[array(255), array(0)]`.
240 """
241
242 backend = [TransformBackends.TORCH, TransformBackends.NUMPY]
243
244 def __init__(self, offset: float, safe: bool = False) -> None:
245 self.offset = offset
246 self.safe = safe
247
248 def __call__(self, img: NdarrayOrTensor, offset: float | None = None) -> NdarrayOrTensor:
249 """
250 Apply the transform to `img`.
251 """
252
253 img = convert_to_tensor(img, track_meta=get_track_meta())
254 offset = self.offset if offset is None else offset
255 out = img + offset
256 out, *_ = convert_data_type(data=out, dtype=img.dtype, safe=self.safe)
257
258 return out
259
260
261class RandShiftIntensity(RandomizableTransform):

Callers 4

__init__Method · 0.90
test_valueMethod · 0.90
test_valueMethod · 0.90
__init__Method · 0.85

Calls

no outgoing calls

Tested by 2

test_valueMethod · 0.72
test_valueMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…