def test_two_connectivity(): # fmt: off expected = np.array([[0, 0, 0, 1, 0], [1, 1, 1, 0, 0], [1, 1, 1, 0, 0]], bool) # fmt: on observed = remove_small_objects(test_image, min_size=7, connectivity=2) assert_array_equal(observed, expected)
def test_in_place(): image = test_image.copy() observed = remove_small_objects(image, min_size=6, in_place=True) assert_equal( observed is image, True, "remove_small_objects in_place argument failed.", )
def test_uint_image(): # fmt: off labeled_image = np.array( [[2, 2, 2, 0, 1], [2, 2, 2, 0, 1], [2, 0, 0, 0, 0], [0, 0, 3, 3, 3]], dtype=np.uint8) expected = np.array( [[2, 2, 2, 0, 0], [2, 2, 2, 0, 0], [2, 0, 0, 0, 0], [0, 0, 3, 3, 3]], dtype=np.uint8) # fmt: on observed = remove_small_objects(labeled_image, min_size=3) assert_array_equal(observed, expected)
def test_negative_input(): negative_int = np.random.randint(-4, -1, size=(5, 5)) with testing.raises(ValueError): remove_small_objects(negative_int)
def test_float_input(): float_test = np.random.rand(5, 5) with testing.raises(TypeError): remove_small_objects(float_test)
def test_single_label_warning(): # fmt: off image = np.array([[0, 0, 0, 1, 0], [1, 1, 1, 0, 0], [1, 1, 1, 0, 0]], int) # fmt: on with expected_warnings(["use a boolean array?"]): remove_small_objects(image, min_size=6)