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

Method test_contour

tests/transforms/test_label_to_contour.py:145–175  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

143
144class TestContour(unittest.TestCase):
145 def test_contour(self):
146 input_param = {"kernel_type": "Laplace"}
147
148 for p in TEST_NDARRAYS:
149 # check 5-dim input data
150 test_cube, expected_output = gen_fixed_cube(p)
151 for cube in test_cube:
152 test_result_cube = LabelToContour(**input_param)(cube)
153 self.assertEqual(test_result_cube.shape, cube.shape)
154
155 channels = cube.shape[0]
156 for channel in range(channels):
157 assert_allclose(test_result_cube[channel, ...], expected_output, type_test="tensor")
158
159 # check 4-dim input data
160 test_img, expected_output = gen_fixed_img(p)
161 for img in test_img:
162 channels = img.shape[0]
163 test_result_img = LabelToContour(**input_param)(img)
164 self.assertEqual(test_result_img.shape, img.shape)
165
166 for channel in range(channels):
167 assert_allclose(test_result_img[channel, ...], expected_output, type_test="tensor")
168
169 # check invalid input data
170 error_input = torch.rand(1, 2)
171 self.assertRaises(ValueError, LabelToContour(**input_param), error_input)
172 error_input = torch.rand(1, 2, 3, 4, 5)
173 self.assertRaises(ValueError, LabelToContour(**input_param), error_input)
174 error_input = np.random.rand(1, 2, 3, 4, 5)
175 self.assertRaises(ValueError, LabelToContour(**input_param), error_input)
176
177
178if __name__ == "__main__":

Callers

nothing calls this directly

Calls 4

LabelToContourClass · 0.90
assert_allcloseFunction · 0.90
gen_fixed_cubeFunction · 0.70
gen_fixed_imgFunction · 0.70

Tested by

no test coverage detected