Args: img: input data to crop samples from based on the ratios of every class, assumes `img` is a channel-first array. label: the label image that is used for finding indices of every class, if None, use `self.label`. image: optional image
(
self,
img: torch.Tensor,
label: torch.Tensor | None = None,
image: torch.Tensor | None = None,
indices: list[NdarrayOrTensor] | None = None,
randomize: bool = True,
lazy: bool | None = None,
)
| 1351 | return False |
| 1352 | |
| 1353 | def __call__( |
| 1354 | self, |
| 1355 | img: torch.Tensor, |
| 1356 | label: torch.Tensor | None = None, |
| 1357 | image: torch.Tensor | None = None, |
| 1358 | indices: list[NdarrayOrTensor] | None = None, |
| 1359 | randomize: bool = True, |
| 1360 | lazy: bool | None = None, |
| 1361 | ) -> list[torch.Tensor]: |
| 1362 | """ |
| 1363 | Args: |
| 1364 | img: input data to crop samples from based on the ratios of every class, assumes `img` is a |
| 1365 | channel-first array. |
| 1366 | label: the label image that is used for finding indices of every class, if None, use `self.label`. |
| 1367 | image: optional image data to help select valid area, can be same as `img` or another image array. |
| 1368 | use ``image > image_threshold`` to select the centers only in valid region. if None, use `self.image`. |
| 1369 | indices: list of indices for every class in the image, used to randomly select crop centers. |
| 1370 | randomize: whether to execute the random operations, default to `True`. |
| 1371 | lazy: a flag to override the lazy behaviour for this call, if set. Defaults to None. |
| 1372 | """ |
| 1373 | if image is None: |
| 1374 | image = self.image |
| 1375 | if randomize: |
| 1376 | if label is None: |
| 1377 | label = self.label |
| 1378 | self.randomize(label, indices, image) |
| 1379 | results: list[torch.Tensor] = [] |
| 1380 | if self.centers is not None: |
| 1381 | img_shape = img.peek_pending_shape() if isinstance(img, MetaTensor) else img.shape[1:] |
| 1382 | roi_size = fall_back_tuple(self.spatial_size, default=img_shape) |
| 1383 | lazy_ = self.lazy if lazy is None else lazy |
| 1384 | for i, center in enumerate(self.centers): |
| 1385 | cropper = SpatialCrop(roi_center=tuple(center), roi_size=roi_size, lazy=lazy_) |
| 1386 | cropped = cropper(img) |
| 1387 | if get_track_meta(): |
| 1388 | ret_: MetaTensor = cropped # type: ignore |
| 1389 | ret_.meta[Key.PATCH_INDEX] = i |
| 1390 | ret_.meta["crop_center"] = center |
| 1391 | self.push_transform(ret_, replace=True, lazy=lazy_) |
| 1392 | results.append(cropped) |
| 1393 | |
| 1394 | return results |
| 1395 | |
| 1396 | |
| 1397 | class ResizeWithPadOrCrop(InvertibleTransform, LazyTransform): |
nothing calls this directly
no test coverage detected