Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` offset: offset value to shift the intensity of image. safe: if `True`, then do safe dtype convert when intensity ove
(
self,
keys: KeysCollection,
offset: float,
safe: bool = False,
factor_key: str | None = None,
meta_keys: KeysCollection | None = None,
meta_key_postfix: str = DEFAULT_POST_FIX,
allow_missing_keys: bool = False,
)
| 311 | backend = ShiftIntensity.backend |
| 312 | |
| 313 | def __init__( |
| 314 | self, |
| 315 | keys: KeysCollection, |
| 316 | offset: float, |
| 317 | safe: bool = False, |
| 318 | factor_key: str | None = None, |
| 319 | meta_keys: KeysCollection | None = None, |
| 320 | meta_key_postfix: str = DEFAULT_POST_FIX, |
| 321 | allow_missing_keys: bool = False, |
| 322 | ) -> None: |
| 323 | """ |
| 324 | Args: |
| 325 | keys: keys of the corresponding items to be transformed. |
| 326 | See also: :py:class:`monai.transforms.compose.MapTransform` |
| 327 | offset: offset value to shift the intensity of image. |
| 328 | safe: if `True`, then do safe dtype convert when intensity overflow. default to `False`. |
| 329 | E.g., `[256, -12]` -> `[array(0), array(244)]`. If `True`, then `[256, -12]` -> `[array(255), array(0)]`. |
| 330 | factor_key: if not None, use it as the key to extract a value from the corresponding |
| 331 | metadata dictionary of `key` at runtime, and multiply the `offset` to shift intensity. |
| 332 | Usually, `IntensityStatsd` transform can pre-compute statistics of intensity values |
| 333 | and store in the metadata. |
| 334 | it also can be a sequence of strings, map to `keys`. |
| 335 | meta_keys: explicitly indicate the key of the corresponding metadata dictionary. |
| 336 | used to extract the factor value is `factor_key` is not None. |
| 337 | for example, for data with key `image`, the metadata by default is in `image_meta_dict`. |
| 338 | the metadata is a dictionary object which contains: filename, original_shape, etc. |
| 339 | it can be a sequence of string, map to the `keys`. |
| 340 | if None, will try to construct meta_keys by `key_{meta_key_postfix}`. |
| 341 | meta_key_postfix: if meta_keys is None, use `key_{postfix}` to fetch the metadata according |
| 342 | to the key data, default is `meta_dict`, the metadata is a dictionary object. |
| 343 | used to extract the factor value is `factor_key` is not None. |
| 344 | allow_missing_keys: don't raise exception if key is missing. |
| 345 | """ |
| 346 | super().__init__(keys, allow_missing_keys) |
| 347 | self.factor_key = ensure_tuple_rep(factor_key, len(self.keys)) |
| 348 | self.meta_keys = ensure_tuple_rep(None, len(self.keys)) if meta_keys is None else ensure_tuple(meta_keys) |
| 349 | if len(self.keys) != len(self.meta_keys): |
| 350 | raise ValueError("meta_keys should have the same length as keys.") |
| 351 | self.meta_key_postfix = ensure_tuple_rep(meta_key_postfix, len(self.keys)) |
| 352 | self.shifter = ShiftIntensity(offset, safe) |
| 353 | |
| 354 | def __call__(self, data) -> dict[Hashable, NdarrayOrTensor]: |
| 355 | d = dict(data) |
nothing calls this directly
no test coverage detected