Crop at the center of image with specified scale of ROI size. This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic ` for more information. Args: roi_scale: specifies the expected scale of image size to crop. e.g. [0.3, 0.4, 0.5]
| 530 | |
| 531 | |
| 532 | class CenterScaleCrop(Crop): |
| 533 | """ |
| 534 | Crop at the center of image with specified scale of ROI size. |
| 535 | |
| 536 | This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic<lazy_resampling>` |
| 537 | for more information. |
| 538 | |
| 539 | Args: |
| 540 | roi_scale: specifies the expected scale of image size to crop. e.g. [0.3, 0.4, 0.5] or a number for all dims. |
| 541 | If its components have non-positive values, will use `1.0` instead, which means the input image size. |
| 542 | lazy: a flag to indicate whether this transform should execute lazily or not. Defaults to False. |
| 543 | """ |
| 544 | |
| 545 | def __init__(self, roi_scale: Sequence[float] | float, lazy: bool = False): |
| 546 | super().__init__(lazy=lazy) |
| 547 | self.roi_scale = roi_scale |
| 548 | |
| 549 | def __call__(self, img: torch.Tensor, lazy: bool | None = None) -> torch.Tensor: # type: ignore[override] |
| 550 | img_size = img.peek_pending_shape() if isinstance(img, MetaTensor) else img.shape[1:] |
| 551 | ndim = len(img_size) |
| 552 | roi_size = [ceil(r * s) for r, s in zip(ensure_tuple_rep(self.roi_scale, ndim), img_size)] |
| 553 | lazy_ = self.lazy if lazy is None else lazy |
| 554 | cropper = CenterSpatialCrop(roi_size=roi_size, lazy=lazy_) |
| 555 | return super().__call__(img=img, slices=cropper.compute_slices(img_size), lazy=lazy_) |
| 556 | |
| 557 | |
| 558 | class RandSpatialCrop(Randomizable, Crop): |
no outgoing calls
no test coverage detected
searching dependent graphs…