Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` roi_center: voxel coordinates for center of the crop ROI, or a string key to look up the coordinates from the da
(
self,
keys: KeysCollection,
roi_center: Sequence[int] | int | str | None = None,
roi_size: Sequence[int] | int | str | None = None,
roi_start: Sequence[int] | int | str | None = None,
roi_end: Sequence[int] | int | str | None = None,
roi_slices: Sequence[slice] | None = None,
allow_missing_keys: bool = False,
lazy: bool = False,
)
| 452 | """ |
| 453 | |
| 454 | def __init__( |
| 455 | self, |
| 456 | keys: KeysCollection, |
| 457 | roi_center: Sequence[int] | int | str | None = None, |
| 458 | roi_size: Sequence[int] | int | str | None = None, |
| 459 | roi_start: Sequence[int] | int | str | None = None, |
| 460 | roi_end: Sequence[int] | int | str | None = None, |
| 461 | roi_slices: Sequence[slice] | None = None, |
| 462 | allow_missing_keys: bool = False, |
| 463 | lazy: bool = False, |
| 464 | ) -> None: |
| 465 | """ |
| 466 | Args: |
| 467 | keys: keys of the corresponding items to be transformed. |
| 468 | See also: :py:class:`monai.transforms.compose.MapTransform` |
| 469 | roi_center: voxel coordinates for center of the crop ROI, or a string key to look up |
| 470 | the coordinates from the data dictionary. |
| 471 | roi_size: size of the crop ROI, if a dimension of ROI size is larger than image size, |
| 472 | will not crop that dimension of the image. Can also be a string key. |
| 473 | roi_start: voxel coordinates for start of the crop ROI, or a string key to look up |
| 474 | the coordinates from the data dictionary. |
| 475 | roi_end: voxel coordinates for end of the crop ROI, if a coordinate is out of image, |
| 476 | use the end coordinate of image. Can also be a string key. |
| 477 | roi_slices: list of slices for each of the spatial dimensions. |
| 478 | allow_missing_keys: don't raise exception if key is missing. |
| 479 | lazy: a flag to indicate whether this transform should execute lazily or not. Defaults to False. |
| 480 | """ |
| 481 | self._roi_center = roi_center |
| 482 | self._roi_size = roi_size |
| 483 | self._roi_start = roi_start |
| 484 | self._roi_end = roi_end |
| 485 | self._roi_slices = roi_slices |
| 486 | self._has_str_roi = any(isinstance(v, str) for v in [roi_center, roi_size, roi_start, roi_end]) |
| 487 | |
| 488 | if not self._has_str_roi: |
| 489 | _roi_t: TypeAlias = Sequence[int] | int | None |
| 490 | cropper = SpatialCrop( |
| 491 | cast(_roi_t, roi_center), |
| 492 | cast(_roi_t, roi_size), |
| 493 | cast(_roi_t, roi_start), |
| 494 | cast(_roi_t, roi_end), |
| 495 | roi_slices, |
| 496 | lazy=lazy, |
| 497 | ) |
| 498 | else: |
| 499 | # Placeholder cropper for the string-key path. Replaced on self.cropper at |
| 500 | # __call__ time once string keys are resolved from the data dictionary. |
| 501 | cropper = SpatialCrop(roi_start=[0], roi_end=[1], lazy=lazy) |
| 502 | super().__init__(keys, cropper=cropper, allow_missing_keys=allow_missing_keys, lazy=lazy) |
| 503 | |
| 504 | @staticmethod |
| 505 | def _resolve_roi_param(val, d): |
nothing calls this directly
no test coverage detected