From 438a9355d6aa0085a9ed7d12afee7c8b2d92351f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20T=C3=BD=C4=8D?= Date: Tue, 11 Nov 2014 00:39:49 +0100 Subject: [PATCH] Fixed bugs so test pass now --- skimage/measure/_ccomp.pyx | 16 ++++++++------- skimage/morphology/tests/test_ccomp.py | 28 +++++++++----------------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/skimage/measure/_ccomp.pyx b/skimage/measure/_ccomp.pyx index cc4a5320..5344aa9a 100644 --- a/skimage/measure/_ccomp.pyx +++ b/skimage/measure/_ccomp.pyx @@ -137,7 +137,7 @@ cdef shape_info get_shape_info(inarr_shape): res.DEX[D_ei] = res.DEX[D_ef] - res.DEX[D_eb] # DEX[D_eb] = one row up, remember? res.DEX[D_ej] = res.DEX[D_ei] + 1 res.DEX[D_ek] = res.DEX[D_ei] + 2 - res.DEX[D_el] = res.DEX[D_ei] - 2 * res.DEX[D_eb] + res.DEX[D_el] = res.DEX[D_ei] - res.DEX[D_eb] res.DEX[D_em] = res.DEX[D_el] + 1 res.DEX[D_en] = res.DEX[D_el] + 2 @@ -470,7 +470,7 @@ cdef void scan2D(DTYPE_t *data_p, DTYPE_t *forest_p, shape_info *shapeinfo, join_trees_wrapper(data_p, forest_p, rindex, DEX[D_eb]) if neighbors == 8: - if x < shapeinfo.x - 1: + if x + 1 < shapeinfo.x: join_trees_wrapper(data_p, forest_p, rindex, DEX[D_ec]) join_trees_wrapper(data_p, forest_p, rindex, DEX[D_ed]) @@ -557,7 +557,7 @@ cdef void scan3D(DTYPE_t *data_p, DTYPE_t *forest_p, shape_info *shapeinfo, join_trees_wrapper(data_p, forest_p, rindex, DEX[D_eb]) if neighbors == 8: - if x < shapeinfo.x - 1: + if x + 1 < shapeinfo.x: join_trees_wrapper(data_p, forest_p, rindex, DEX[D_ec]) join_trees_wrapper(data_p, forest_p, rindex, DEX[D_ed]) @@ -579,9 +579,11 @@ cdef void scan3D(DTYPE_t *data_p, DTYPE_t *forest_p, shape_info *shapeinfo, if x + 1 < shapeinfo.x: join_trees_wrapper(data_p, forest_p, rindex, DEX[D_ek]) - join_trees_wrapper(data_p, forest_p, rindex, DEX[D_el]) + if y + 1 < shapeinfo.y: + join_trees_wrapper(data_p, forest_p, rindex, DEX[D_el]) - join_trees_wrapper(data_p, forest_p, rindex, DEX[D_em]) + join_trees_wrapper(data_p, forest_p, rindex, DEX[D_em]) - if x + 1 < shapeinfo.x: - join_trees_wrapper(data_p, forest_p, rindex, DEX[D_en]) + if x + 1 < shapeinfo.x: + join_trees_wrapper(data_p, forest_p, + rindex, DEX[D_en]) diff --git a/skimage/morphology/tests/test_ccomp.py b/skimage/morphology/tests/test_ccomp.py index c7c52d96..490c32d3 100644 --- a/skimage/morphology/tests/test_ccomp.py +++ b/skimage/morphology/tests/test_ccomp.py @@ -76,7 +76,8 @@ class TestConnectedComponents: [0, 0, 6], [5, 5, 5]]) - assert_array_equal(label(x, background=0), + res = label(x, background=0) + assert_array_equal(res, [[-1, -1, 0], [-1, -1, 0], [+1, 1, 1]]) @@ -132,16 +133,16 @@ class TestConnectedComponents3d: [0, 1, 1, 3, 3], [1, 5, 1, 1, 7]]) - self.labels[2] = np.array([[1, 1, 8, 8, 10], - [9, 1, 4, 8, 8], - [9, 1, 7, 8, 7], - [9, 5, 7, 7, 7]]) + self.labels[2] = np.array([[1, 1, 8, 8, 9], + [10, 1, 4, 8, 8], + [10, 1, 7, 8, 7], + [10, 5, 7, 7, 7]]) def test_basic(self): labels = label(self.x) assert_array_equal(labels, self.labels) - assert self.x[0, 0, 2] == 3, \ + assert self.x[0, 0, 2] == 2, \ "Data was modified!" def test_random(self): @@ -218,7 +219,8 @@ class TestConnectedComponents3d: [1, BGL, BGL], [BGL, BGL, BGL]]) - assert_array_equal(label(x, background=0), lb) + res = label(x, background=0) + assert_array_equal(res, lb) def test_background_one_region_center(self): x = np.zeros((3, 3, 3), int) @@ -241,14 +243,4 @@ class TestConnectedComponents3d: if __name__ == "__main__": - #run_module_suite() - lol = TestConnectedComponents3d() - lol.setup() - lol.test_basic() # 1 failiure - lol.test_random() - #lol.test_diag() # epic failiure - #lol.test_4_vs_8() # label8 epic - #lol.test_background() - #lol.test_background_two_regions() - lol.test_background_one_region_center() - lol.test_return_num() + run_module_suite()