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

Method randomize

monai/transforms/croppad/array.py:1132–1161  ·  view source on GitHub ↗
(
        self,
        label: torch.Tensor | None = None,
        fg_indices: NdarrayOrTensor | None = None,
        bg_indices: NdarrayOrTensor | None = None,
        image: torch.Tensor | None = None,
    )

Source from the content-addressed store, hash-verified

1130 self.allow_smaller = allow_smaller
1131
1132 def randomize(
1133 self,
1134 label: torch.Tensor | None = None,
1135 fg_indices: NdarrayOrTensor | None = None,
1136 bg_indices: NdarrayOrTensor | None = None,
1137 image: torch.Tensor | None = None,
1138 ) -> None:
1139 fg_indices_ = self.fg_indices if fg_indices is None else fg_indices
1140 bg_indices_ = self.bg_indices if bg_indices is None else bg_indices
1141 if fg_indices_ is None or bg_indices_ is None:
1142 if label is None:
1143 raise ValueError("label must be provided.")
1144 fg_indices_, bg_indices_ = map_binary_to_indices(label, image, self.image_threshold)
1145 _shape = None
1146 if label is not None:
1147 _shape = label.peek_pending_shape() if isinstance(label, MetaTensor) else label.shape[1:]
1148 elif image is not None:
1149 _shape = image.peek_pending_shape() if isinstance(image, MetaTensor) else image.shape[1:]
1150 if _shape is None:
1151 raise ValueError("label or image must be provided to get the spatial shape.")
1152 self.centers = generate_pos_neg_label_crop_centers(
1153 self.spatial_size,
1154 self.num_samples,
1155 self.pos_ratio,
1156 _shape,
1157 fg_indices_,
1158 bg_indices_,
1159 self.R,
1160 self.allow_smaller,
1161 )
1162
1163 @LazyTransform.lazy.setter # type: ignore
1164 def lazy(self, _val: bool):

Callers 1

__call__Method · 0.95

Calls 3

map_binary_to_indicesFunction · 0.90
peek_pending_shapeMethod · 0.80

Tested by

no test coverage detected