def test_correct_results(self, degrees, keep_size, mode, padding_mode, align_corners): rotate_fn = RandRotate( range_x=degrees, prob=1.0, keep_size=keep_size, mode=mode, padding_mode=padding_mode, align_corners=align_corners, ) rotate_fn.set_random_state(243) rotated = rotate_fn(self.imt[0]) _order = 0 if mode == "nearest" else 1 if mode == "border": _mode = "nearest" elif mode == "reflection": _mode = "reflect" else: _mode = "constant" angle = rotate_fn.x expected = scipy.ndimage.rotate( self.imt[0, 0], -np.rad2deg(angle), (0, 1), not keep_size, order=_order, mode=_mode, prefilter=False ) expected = np.stack(expected).astype(np.float32) good = np.sum(np.isclose(expected, rotated[0], atol=1e-3)) self.assertLessEqual(np.abs(good - expected.size), 5, "diff at most 5 pixels")
def test_correct_results(self, degrees, keep_size, order, mode, align_corners): rotate_fn = RandRotate(range_x=degrees, prob=1.0, keep_size=keep_size, interp_order=order, mode=mode, align_corners=align_corners) rotate_fn.set_random_state(243) rotated = rotate_fn(self.imt[0]) _order = 0 if order == "nearest" else 1 if mode == "border": _mode = "nearest" elif mode == "reflection": _mode = "reflect" else: _mode = "constant" angle = rotate_fn.x expected = scipy.ndimage.rotate(self.imt[0, 0], -angle, (0, 1), not keep_size, order=_order, mode=_mode, prefilter=False) expected = np.stack(expected).astype(np.float32) np.testing.assert_allclose(expected, rotated[0])
def test_correct_results(self, degrees, spatial_axes, reshape, order, mode, cval, prefilter): rotate_fn = RandRotate( degrees, prob=1.0, spatial_axes=spatial_axes, reshape=reshape, interp_order=order, mode=mode, cval=cval, prefilter=prefilter, ) rotate_fn.set_random_state(243) rotated = rotate_fn(self.imt[0]) angle = rotate_fn.angle expected = list() for channel in self.imt[0]: expected.append( scipy.ndimage.rotate(channel, angle, spatial_axes, reshape, order=order, mode=mode, cval=cval, prefilter=prefilter)) expected = np.stack(expected).astype(np.float32) self.assertTrue(np.allclose(expected, rotated))
def test_correct_results(self, x, y, z, keep_size, mode, padding_mode, align_corners, expected): rotate_fn = RandRotate( range_x=x, range_y=y, range_z=z, prob=1.0, keep_size=keep_size, mode=mode, padding_mode=padding_mode, align_corners=align_corners, ) rotate_fn.set_random_state(243) rotated = rotate_fn(self.imt[0]) np.testing.assert_allclose(rotated.shape, expected)
def test_correct_results(self, im_type, x, y, z, keep_size, mode, padding_mode, align_corners, expected): rotate_fn = RandRotate( range_x=x, range_y=y, range_z=z, prob=1.0, keep_size=keep_size, mode=mode, padding_mode=padding_mode, align_corners=align_corners, dtype=np.float64, ) rotate_fn.set_random_state(243) rotated = rotate_fn(im_type(self.imt[0])) torch.testing.assert_allclose(rotated.shape, expected, rtol=1e-7, atol=0)
def test_correct_results(self, im_type, x, y, z, keep_size, mode, padding_mode, align_corners, expected): rotate_fn = RandRotate( range_x=x, range_y=y, range_z=z, prob=1.0, keep_size=keep_size, mode=mode, padding_mode=padding_mode, align_corners=align_corners, dtype=np.float64, ) rotate_fn.set_random_state(243) im = im_type(self.imt[0]) rotated = rotate_fn(im) torch.testing.assert_allclose(rotated.shape, expected, rtol=1e-7, atol=0) test_local_inversion(rotate_fn, rotated, im) set_track_meta(False) rotated = rotate_fn(im) self.assertNotIsInstance(rotated, MetaTensor) self.assertIsInstance(rotated, torch.Tensor) set_track_meta(True)