MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / RandSpatialCropd

Class RandSpatialCropd

monai/transforms/croppad/dictionary.py:656–701  ·  view source on GitHub ↗

Dictionary-based version :py:class:`monai.transforms.RandSpatialCrop`. Crop image with random size or specific size ROI. It can crop at a random position as center or at the image center. And allows to set the minimum and maximum size to limit the randomly generated ROI. Suppose all

Source from the content-addressed store, hash-verified

654
655
656class RandSpatialCropd(RandCropd):
657 """
658 Dictionary-based version :py:class:`monai.transforms.RandSpatialCrop`.
659 Crop image with random size or specific size ROI. It can crop at a random position as
660 center or at the image center. And allows to set the minimum and maximum size to limit the randomly
661 generated ROI. Suppose all the expected fields specified by `keys` have same shape.
662
663 Note: even `random_size=False`, if a dimension of the expected ROI size is larger than the input image size,
664 will not crop that dimension. So the cropped result may be smaller than the expected ROI, and the cropped
665 results of several images may not have exactly the same shape.
666
667 This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic<lazy_resampling>`
668 for more information.
669
670 Args:
671 keys: keys of the corresponding items to be transformed.
672 See also: monai.transforms.MapTransform
673 roi_size: if `random_size` is True, it specifies the minimum crop region.
674 if `random_size` is False, it specifies the expected ROI size to crop. e.g. [224, 224, 128]
675 if a dimension of ROI size is larger than image size, will not crop that dimension of the image.
676 If its components have non-positive values, the corresponding size of input image will be used.
677 for example: if the spatial size of input data is [40, 40, 40] and `roi_size=[32, 64, -1]`,
678 the spatial size of output data will be [32, 40, 40].
679 max_roi_size: if `random_size` is True and `roi_size` specifies the min crop region size, `max_roi_size`
680 can specify the max crop region size. if None, defaults to the input image size.
681 if its components have non-positive values, the corresponding size of input image will be used.
682 random_center: crop at random position as center or the image center.
683 random_size: crop with random size or specific size ROI.
684 if True, the actual size is sampled from:
685 `randint(roi_scale * image spatial size, max_roi_scale * image spatial size + 1)`.
686 allow_missing_keys: don&#x27;t raise exception if key is missing.
687 lazy: a flag to indicate whether this transform should execute lazily or not. Defaults to False.
688 """
689
690 def __init__(
691 self,
692 keys: KeysCollection,
693 roi_size: Sequence[int] | int,
694 max_roi_size: Sequence[int] | int | None = None,
695 random_center: bool = True,
696 random_size: bool = False,
697 allow_missing_keys: bool = False,
698 lazy: bool = False,
699 ) -> None:
700 cropper = RandSpatialCrop(roi_size, max_roi_size, random_center, random_size, lazy=lazy)
701 super().__init__(keys, cropper=cropper, allow_missing_keys=allow_missing_keys, lazy=lazy)
702
703
704class RandScaleCropd(RandCropd):

Callers 2

test_inverse.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…