def test_one_components(self): dut = fltr.LargestNConnectedComponents(1, False) result = dut.execute(self.image) self.assertEqual(result.GetPixel((4, 0)), 1) self.assertEqual(result.GetPixel((4, 1)), 1) self.assertEqual(result.GetPixel((4, 2)), 1) result_array = sitk.GetArrayFromImage(result) self.assertEqual(result_array.sum(), 3)
def test_consecutive_labels(self): dut = fltr.LargestNConnectedComponents(3, True) result = dut.execute(self.image) self.assertEqual(result.GetPixel((0, 0)), 3) self.assertEqual(result.GetPixel((2, 0)), 2) self.assertEqual(result.GetPixel((2, 1)), 2) self.assertEqual(result.GetPixel((4, 0)), 1) self.assertEqual(result.GetPixel((4, 1)), 1) self.assertEqual(result.GetPixel((4, 2)), 1) result_array = sitk.GetArrayFromImage(result) self.assertEqual(result_array.sum(), 10)
def test_zero_components(self): with self.assertRaises(ValueError): fltr.LargestNConnectedComponents(0, False)