Args: keys: keys of the corresponding items to be transformed. See also: :py:class:`monai.transforms.compose.MapTransform` source_key: data source to generate the bounding box of foreground, can be image or label, etc. select_fn: function
(
self,
keys: KeysCollection,
source_key: str,
select_fn: Callable = is_positive,
channel_indices: IndexSelection | None = None,
margin: Sequence[int] | int = 0,
allow_smaller: bool = False,
k_divisible: Sequence[int] | int = 1,
mode: SequenceStr = PytorchPadMode.CONSTANT,
start_coord_key: str | None = "foreground_start_coord",
end_coord_key: str | None = "foreground_end_coord",
allow_missing_keys: bool = False,
lazy: bool = False,
**pad_kwargs,
)
| 848 | """ |
| 849 | |
| 850 | def __init__( |
| 851 | self, |
| 852 | keys: KeysCollection, |
| 853 | source_key: str, |
| 854 | select_fn: Callable = is_positive, |
| 855 | channel_indices: IndexSelection | None = None, |
| 856 | margin: Sequence[int] | int = 0, |
| 857 | allow_smaller: bool = False, |
| 858 | k_divisible: Sequence[int] | int = 1, |
| 859 | mode: SequenceStr = PytorchPadMode.CONSTANT, |
| 860 | start_coord_key: str | None = "foreground_start_coord", |
| 861 | end_coord_key: str | None = "foreground_end_coord", |
| 862 | allow_missing_keys: bool = False, |
| 863 | lazy: bool = False, |
| 864 | **pad_kwargs, |
| 865 | ) -> None: |
| 866 | """ |
| 867 | Args: |
| 868 | keys: keys of the corresponding items to be transformed. |
| 869 | See also: :py:class:`monai.transforms.compose.MapTransform` |
| 870 | source_key: data source to generate the bounding box of foreground, can be image or label, etc. |
| 871 | select_fn: function to select expected foreground, default is to select values > 0. |
| 872 | channel_indices: if defined, select foreground only on the specified channels |
| 873 | of image. if None, select foreground on the whole image. |
| 874 | margin: add margin value to spatial dims of the bounding box, if only 1 value provided, use it for all dims. |
| 875 | allow_smaller: when computing box size with `margin`, whether to allow the image edges to be smaller than the |
| 876 | final box edges. If `False`, part of a padded output box might be outside of the original image, if `True`, |
| 877 | the image edges will be used as the box edges. Default to `False`. |
| 878 | The default value is changed from `True` to `False` in v1.5.0. |
| 879 | k_divisible: make each spatial dimension to be divisible by k, default to 1. |
| 880 | if `k_divisible` is an int, the same `k` be applied to all the input spatial dimensions. |
| 881 | mode: available modes for numpy array:{``"constant"``, ``"edge"``, ``"linear_ramp"``, ``"maximum"``, |
| 882 | ``"mean"``, ``"median"``, ``"minimum"``, ``"reflect"``, ``"symmetric"``, ``"wrap"``, ``"empty"``} |
| 883 | available modes for PyTorch Tensor: {``"constant"``, ``"reflect"``, ``"replicate"``, ``"circular"``}. |
| 884 | One of the listed string values or a user supplied function. Defaults to ``"constant"``. |
| 885 | See also: https://numpy.org/doc/1.18/reference/generated/numpy.pad.html |
| 886 | https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html |
| 887 | it also can be a sequence of string, each element corresponds to a key in ``keys``. |
| 888 | start_coord_key: key to record the start coordinate of spatial bounding box for foreground. |
| 889 | end_coord_key: key to record the end coordinate of spatial bounding box for foreground. |
| 890 | allow_missing_keys: don't raise exception if key is missing. |
| 891 | lazy: a flag to indicate whether this transform should execute lazily or not. Defaults to False. |
| 892 | pad_kwargs: other arguments for the `np.pad` or `torch.pad` function. |
| 893 | note that `np.pad` treats channel dimension as the first dimension. |
| 894 | |
| 895 | """ |
| 896 | self.source_key = source_key |
| 897 | self.start_coord_key = start_coord_key |
| 898 | self.end_coord_key = end_coord_key |
| 899 | cropper = CropForeground( |
| 900 | select_fn=select_fn, |
| 901 | channel_indices=channel_indices, |
| 902 | margin=margin, |
| 903 | allow_smaller=allow_smaller, |
| 904 | k_divisible=k_divisible, |
| 905 | lazy=lazy, |
| 906 | **pad_kwargs, |
| 907 | ) |
nothing calls this directly
no test coverage detected