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

Class SpatialCropd

monai/transforms/croppad/dictionary.py:420–595  ·  view source on GitHub ↗

Dictionary-based wrapper of :py:class:`monai.transforms.SpatialCrop`. General purpose cropper to produce sub-volume region of interest (ROI). If a dimension of the expected ROI size is larger than the input image size, will not crop that dimension. So the cropped result may be small

Source from the content-addressed store, hash-verified

418
419
420class SpatialCropd(Cropd):
421 """
422 Dictionary-based wrapper of :py:class:`monai.transforms.SpatialCrop`.
423 General purpose cropper to produce sub-volume region of interest (ROI).
424 If a dimension of the expected ROI size is larger than the input image size, will not crop that dimension.
425 So the cropped result may be smaller than the expected ROI, and the cropped results of several images may
426 not have exactly the same shape.
427 It can support to crop ND spatial (channel-first) data.
428
429 The cropped region can be parameterised in various ways:
430 - a list of slices for each spatial dimension (allows for use of -ve indexing and `None`)
431 - a spatial center and size
432 - the start and end coordinates of the ROI
433
434 ROI parameters (``roi_center``, ``roi_size``, ``roi_start``, ``roi_end``) can also be specified as
435 string dictionary keys. When a string is provided, the actual coordinate values are read from the
436 data dictionary at call time. This enables pipelines where coordinates are computed by earlier
437 transforms (e.g., :py:class:`monai.transforms.TransformPointsWorldToImaged`) and stored in the
438 data dictionary under the given key.
439
440 Example::
441
442 from monai.transforms import Compose, TransformPointsWorldToImaged, SpatialCropd
443
444 pipeline = Compose([
445 TransformPointsWorldToImaged(keys="roi_start", refer_keys="image"),
446 TransformPointsWorldToImaged(keys="roi_end", refer_keys="image"),
447 SpatialCropd(keys="image", roi_start="roi_start", roi_end="roi_end"),
448 ])
449
450 This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic<lazy_resampling>`
451 for more information.
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.

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…