Dictionary-based version :py:class:`monai.transforms.RandShiftIntensity`.
| 364 | |
| 365 | |
| 366 | class RandShiftIntensityd(RandomizableTransform, MapTransform): |
| 367 | """ |
| 368 | Dictionary-based version :py:class:`monai.transforms.RandShiftIntensity`. |
| 369 | """ |
| 370 | |
| 371 | backend = RandShiftIntensity.backend |
| 372 | |
| 373 | def __init__( |
| 374 | self, |
| 375 | keys: KeysCollection, |
| 376 | offsets: tuple[float, float] | float, |
| 377 | safe: bool = False, |
| 378 | factor_key: str | None = None, |
| 379 | meta_keys: KeysCollection | None = None, |
| 380 | meta_key_postfix: str = DEFAULT_POST_FIX, |
| 381 | prob: float = 0.1, |
| 382 | channel_wise: bool = False, |
| 383 | allow_missing_keys: bool = False, |
| 384 | ) -> None: |
| 385 | """ |
| 386 | Args: |
| 387 | keys: keys of the corresponding items to be transformed. |
| 388 | See also: :py:class:`monai.transforms.compose.MapTransform` |
| 389 | offsets: offset range to randomly shift. |
| 390 | if single number, offset value is picked from (-offsets, offsets). |
| 391 | safe: if `True`, then do safe dtype convert when intensity overflow. default to `False`. |
| 392 | E.g., `[256, -12]` -> `[array(0), array(244)]`. If `True`, then `[256, -12]` -> `[array(255), array(0)]`. |
| 393 | factor_key: if not None, use it as the key to extract a value from the corresponding |
| 394 | metadata dictionary of `key` at runtime, and multiply the random `offset` to shift intensity. |
| 395 | Usually, `IntensityStatsd` transform can pre-compute statistics of intensity values |
| 396 | and store in the metadata. |
| 397 | it also can be a sequence of strings, map to `keys`. |
| 398 | meta_keys: explicitly indicate the key of the corresponding metadata dictionary. |
| 399 | used to extract the factor value is `factor_key` is not None. |
| 400 | for example, for data with key `image`, the metadata by default is in `image_meta_dict`. |
| 401 | the metadata is a dictionary object which contains: filename, original_shape, etc. |
| 402 | it can be a sequence of string, map to the `keys`. |
| 403 | if None, will try to construct meta_keys by `key_{meta_key_postfix}`. |
| 404 | meta_key_postfix: if meta_keys is None, use `key_{postfix}` to fetch the metadata according |
| 405 | to the key data, default is `meta_dict`, the metadata is a dictionary object. |
| 406 | used to extract the factor value is `factor_key` is not None. |
| 407 | prob: probability of shift. |
| 408 | (Default 0.1, with 10% probability it returns an array shifted intensity.) |
| 409 | channel_wise: if True, shift intensity on each channel separately. For each channel, a random offset will be chosen. |
| 410 | Please ensure that the first dimension represents the channel of the image if True. |
| 411 | allow_missing_keys: don't raise exception if key is missing. |
| 412 | """ |
| 413 | MapTransform.__init__(self, keys, allow_missing_keys) |
| 414 | RandomizableTransform.__init__(self, prob) |
| 415 | |
| 416 | self.factor_key = ensure_tuple_rep(factor_key, len(self.keys)) |
| 417 | self.meta_keys = ensure_tuple_rep(None, len(self.keys)) if meta_keys is None else ensure_tuple(meta_keys) |
| 418 | if len(self.keys) != len(self.meta_keys): |
| 419 | raise ValueError("meta_keys should have the same length as keys.") |
| 420 | self.meta_key_postfix = ensure_tuple_rep(meta_key_postfix, len(self.keys)) |
| 421 | self.shifter = RandShiftIntensity(offsets=offsets, safe=safe, prob=1.0, channel_wise=channel_wise) |
| 422 | |
| 423 | def set_random_state( |
no outgoing calls
searching dependent graphs…