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

Method __init__

monai/transforms/intensity/array.py:268–290  ·  view source on GitHub ↗

Args: offsets: offset range to randomly shift. if single number, offset value is picked from (-offsets, offsets). safe: if `True`, then do safe dtype convert when intensity overflow. default to `False`. E.g., `[256, -12]` -> `[array(0)

(
        self, offsets: tuple[float, float] | float, safe: bool = False, prob: float = 0.1, channel_wise: bool = False
    )

Source from the content-addressed store, hash-verified

266 backend = [TransformBackends.TORCH, TransformBackends.NUMPY]
267
268 def __init__(
269 self, offsets: tuple[float, float] | float, safe: bool = False, prob: float = 0.1, channel_wise: bool = False
270 ) -> None:
271 """
272 Args:
273 offsets: offset range to randomly shift.
274 if single number, offset value is picked from (-offsets, offsets).
275 safe: if `True`, then do safe dtype convert when intensity overflow. default to `False`.
276 E.g., `[256, -12]` -> `[array(0), array(244)]`. If `True`, then `[256, -12]` -> `[array(255), array(0)]`.
277 prob: probability of shift.
278 channel_wise: if True, shift intensity on each channel separately. For each channel, a random offset will be chosen.
279 Please ensure that the first dimension represents the channel of the image if True.
280 """
281 RandomizableTransform.__init__(self, prob)
282 if isinstance(offsets, (int, float)):
283 self.offsets = (min(-offsets, offsets), max(-offsets, offsets))
284 elif len(offsets) != 2:
285 raise ValueError(f"offsets should be a number or pair of numbers, got {offsets}.")
286 else:
287 self.offsets = (min(offsets), max(offsets))
288 self._offset = self.offsets[0]
289 self.channel_wise = channel_wise
290 self._shifter = ShiftIntensity(self._offset, safe)
291
292 def randomize(self, data: Any | None = None) -> None:
293 super().randomize(None)

Callers

nothing calls this directly

Calls 4

minFunction · 0.85
maxFunction · 0.85
ShiftIntensityClass · 0.85
__init__Method · 0.45

Tested by

no test coverage detected