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

Method test_correct_results

tests/transforms/test_rotate.py:100–133  ·  view source on GitHub ↗
(self, im_type, angle, keep_size, mode, padding_mode, align_corners)

Source from the content-addressed store, hash-verified

98class TestRotate3D(NumpyImageTestCase3D):
99 @parameterized.expand(TEST_CASES_3D)
100 def test_correct_results(self, im_type, angle, keep_size, mode, padding_mode, align_corners):
101 init_param = {
102 "angle": [angle, 0, 0],
103 "keep_size": keep_size,
104 "mode": mode,
105 "padding_mode": padding_mode,
106 "align_corners": align_corners,
107 "dtype": np.float64,
108 }
109 rotate_fn = Rotate(**init_param)
110 call_param = {"img": im_type(self.imt[0])}
111 rotated = rotate_fn(**call_param)
112 test_resampler_lazy(rotate_fn, rotated, init_param, call_param)
113 if keep_size:
114 np.testing.assert_allclose(self.imt[0].shape, rotated.shape)
115 _order = 0 if mode == "nearest" else 1
116 if padding_mode == "border":
117 _mode = "nearest"
118 elif padding_mode == "reflection":
119 _mode = "reflect"
120 else:
121 _mode = "constant"
122
123 expected = []
124 for channel in self.imt[0]:
125 expected.append(
126 scipy.ndimage.rotate(
127 channel, -np.rad2deg(angle), (1, 2), not keep_size, order=_order, mode=_mode, prefilter=False
128 )
129 )
130 expected = np.stack(expected).astype(np.float32)
131 rotated = rotated.cpu() if isinstance(rotated, torch.Tensor) else rotated
132 n_good = np.sum(np.isclose(expected, rotated, atol=1e-3))
133 self.assertLessEqual(expected.size - n_good, 5, "diff at most 5 pixels")
134
135 @parameterized.expand(TEST_CASES_SHAPE_3D)
136 def test_correct_shape(self, im_type, angle, mode, padding_mode, align_corners):

Callers

nothing calls this directly

Calls 4

RotateClass · 0.90
test_resampler_lazyFunction · 0.90
astypeMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected