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

Class RandRotate90

monai/transforms/spatial/array.py:1236–1301  ·  view source on GitHub ↗

With probability `prob`, input arrays are rotated by 90 degrees in the plane specified by `spatial_axes`. This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic ` for more information.

Source from the content-addressed store, hash-verified

1234
1235
1236class RandRotate90(RandomizableTransform, InvertibleTransform, LazyTransform):
1237 """
1238 With probability `prob`, input arrays are rotated by 90 degrees
1239 in the plane specified by `spatial_axes`.
1240
1241 This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic<lazy_resampling>`
1242 for more information.
1243 """
1244
1245 backend = Rotate90.backend
1246
1247 def __init__(
1248 self, prob: float = 0.1, max_k: int = 3, spatial_axes: tuple[int, int] = (0, 1), lazy: bool = False
1249 ) -> None:
1250 """
1251 Args:
1252 prob: probability of rotating.
1253 (Default 0.1, with 10% probability it returns a rotated array)
1254 max_k: number of rotations will be sampled from `np.random.randint(max_k) + 1`, (Default 3).
1255 spatial_axes: 2 int numbers, defines the plane to rotate with 2 spatial axes.
1256 Default: (0, 1), this is the first two axis in spatial dimensions.
1257 lazy: a flag to indicate whether this transform should execute lazily or not.
1258 Defaults to False
1259 """
1260 RandomizableTransform.__init__(self, prob)
1261 LazyTransform.__init__(self, lazy=lazy)
1262 self.max_k = max_k
1263 self.spatial_axes = spatial_axes
1264
1265 self._rand_k = 0
1266
1267 def randomize(self, data: Any | None = None) -> None:
1268 super().randomize(None)
1269 if not self._do_transform:
1270 return None
1271 self._rand_k = self.R.randint(self.max_k) + 1
1272
1273 def __call__(self, img: torch.Tensor, randomize: bool = True, lazy: bool | None = None) -> torch.Tensor:
1274 """
1275 Args:
1276 img: channel first array, must have shape: (num_channels, H[, W, ..., ]),
1277 randomize: whether to execute `randomize()` function first, default to True.
1278 lazy: a flag to indicate whether this transform should execute lazily or not
1279 during this call. Setting this to False or True overrides the ``lazy`` flag set
1280 during initialization for this call. Defaults to None.
1281 """
1282
1283 if randomize:
1284 self.randomize()
1285
1286 lazy_ = self.lazy if lazy is None else lazy
1287 if self._do_transform:
1288 xform = Rotate90(self._rand_k, self.spatial_axes, lazy=lazy_)
1289 out = xform(img)
1290 else:
1291 out = convert_to_tensor(img, track_meta=get_track_meta())
1292
1293 self.push_transform(out, replace=True, lazy=lazy_)

Callers 8

run_testFunction · 0.90
test_decollate.pyFile · 0.90
test_defaultMethod · 0.90
test_kMethod · 0.90
test_spatial_axesMethod · 0.90
test_invertMethod · 0.90

Calls

no outgoing calls

Tested by 6

run_testFunction · 0.72
test_defaultMethod · 0.72
test_kMethod · 0.72
test_spatial_axesMethod · 0.72
test_invertMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…