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

Class RandSpatialCropSamplesd

monai/transforms/croppad/dictionary.py:747–831  ·  view source on GitHub ↗

Dictionary-based version :py:class:`monai.transforms.RandSpatialCropSamples`. Crop image with random size or specific size ROI to generate a list of N samples. It can crop at a random position as center or at the image center. And allows to set the minimum size to limit the randomly

Source from the content-addressed store, hash-verified

745
746
747class RandSpatialCropSamplesd(Randomizable, MapTransform, LazyTransform, MultiSampleTrait):
748 """
749 Dictionary-based version :py:class:`monai.transforms.RandSpatialCropSamples`.
750 Crop image with random size or specific size ROI to generate a list of N samples.
751 It can crop at a random position as center or at the image center. And allows to set
752 the minimum size to limit the randomly generated ROI. Suppose all the expected fields
753 specified by `keys` have same shape, and add `patch_index` to the corresponding metadata.
754 It will return a list of dictionaries for all the cropped images.
755
756 Note: even `random_size=False`, if a dimension of the expected ROI size is larger than the input image size,
757 will not crop that dimension. So the cropped result may be smaller than the expected ROI, and the cropped
758 results of several images may not have exactly the same shape.
759
760 This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic<lazy_resampling>`
761 for more information.
762
763 Args:
764 keys: keys of the corresponding items to be transformed.
765 See also: monai.transforms.MapTransform
766 roi_size: if `random_size` is True, it specifies the minimum crop region.
767 if `random_size` is False, it specifies the expected ROI size to crop. e.g. [224, 224, 128]
768 if a dimension of ROI size is larger than image size, will not crop that dimension of the image.
769 If its components have non-positive values, the corresponding size of input image will be used.
770 for example: if the spatial size of input data is [40, 40, 40] and `roi_size=[32, 64, -1]`,
771 the spatial size of output data will be [32, 40, 40].
772 num_samples: number of samples (crop regions) to take in the returned list.
773 max_roi_size: if `random_size` is True and `roi_size` specifies the min crop region size, `max_roi_size`
774 can specify the max crop region size. if None, defaults to the input image size.
775 if its components have non-positive values, the corresponding size of input image will be used.
776 random_center: crop at random position as center or the image center.
777 random_size: crop with random size or specific size ROI.
778 The actual size is sampled from `randint(roi_size, img_size)`.
779 allow_missing_keys: don&#x27;t raise exception if key is missing.
780 lazy: a flag to indicate whether this transform should execute lazily or not. Defaults to False.
781
782 Raises:
783 ValueError: When ``num_samples`` is nonpositive.
784
785 """
786
787 backend = RandSpatialCropSamples.backend
788
789 def __init__(
790 self,
791 keys: KeysCollection,
792 roi_size: Sequence[int] | int,
793 num_samples: int,
794 max_roi_size: Sequence[int] | int | None = None,
795 random_center: bool = True,
796 random_size: bool = False,
797 allow_missing_keys: bool = False,
798 lazy: bool = False,
799 ) -> None:
800 MapTransform.__init__(self, keys, allow_missing_keys)
801 LazyTransform.__init__(self, lazy)
802 self.cropper = RandSpatialCropSamples(
803 roi_size, num_samples, max_roi_size, random_center, random_size, lazy=lazy
804 )

Callers 5

test_shapeMethod · 0.90
test_deep_copyMethod · 0.90
test_pending_opsMethod · 0.90
test_inverse.pyFile · 0.90
test_samplesMethod · 0.90

Calls

no outgoing calls

Tested by 4

test_shapeMethod · 0.72
test_deep_copyMethod · 0.72
test_pending_opsMethod · 0.72
test_samplesMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…