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
| 230 | |
| 231 | |
| 232 | class 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 | |
| 261 | class RandShiftIntensity(RandomizableTransform): |
no outgoing calls
searching dependent graphs…