def test_value(self): c = ConnectedRegion(shape=(2, 2)) assert_equal(crh.get_value(c), 0) crh.set_value(c, 5) assert_equal(crh.get_value(c), 5) crh.set_value(c, 0) assert_equal(crh.get_value(c), 0)
def test_maximal(self): c = ConnectedRegion(shape=(3, 3), value=1, rowptr=[0, 2], colptr=[0, 1]) img = crh.todense(c) assert_equal(crh.boundary_maximum(c, img), 0) crh.set_value(c, -1) assert_equal(crh.boundary_maximum(c, img), 0)
def test_connected_regions(self): labels, regions = lulu.connected_regions(self.img) assert_array_equal(labels, self.img) assert_equal(len(regions), 3) crh.set_value(regions[0], 5) assert_array_equal(crh.todense(regions[0]), [[5, 5, 5, 5, 0], [5, 0, 0, 0, 0], [5, 0, 0, 0, 0], [5, 5, 5, 5, 0], [5, 5, 5, 5, 0]]) assert_array_equal(crh.todense(regions[1]), [[0, 0, 0, 0, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0, 1]]) assert_array_equal(crh.todense(regions[2]), [[0, 0, 0, 0, 0], [0, 2, 2, 2, 0], [0, 2, 2, 2, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
def test_minimal(self): c = ConnectedRegion(shape=(3, 3), value=-1, rowptr=[0, 2], colptr=[0, 1]) img = crh.todense(c) assert_equal(crh.boundary_minimum(c, img), 0) crh.set_value(c, 1) assert_equal(crh.boundary_minimum(c, img), 0)
def test_internal_build_ops(self): c = ConnectedRegion(shape=(2, 2), rowptr=[0]) assert_equal(crh._current_row(c), 0) crh._append_colptr(c, 0, 1) crh._new_row(c) assert_equal(crh._current_row(c), 1) crh._append_colptr(c, 1, 2) crh._new_row(c) crh.set_value(c, 5) assert_array_equal(crh.todense(c), [[5, 0], [0, 5]])