Example #1
0
def test_discontiguous_out_array():
    image = np.array([[5, 6, 2], [7, 2, 2], [3, 5, 1]], np.uint8)
    out_array_big = np.zeros((5, 5), np.uint8)
    out_array = out_array_big[::2, ::2]
    expected_dilation = np.array(
        [[7, 0, 6, 0, 6], [0, 0, 0, 0, 0], [7, 0, 7, 0, 2], [0, 0, 0, 0, 0],
         [7, 0, 5, 0, 5]], np.uint8)
    expected_erosion = np.array(
        [[5, 0, 2, 0, 2], [0, 0, 0, 0, 0], [2, 0, 2, 0, 1], [0, 0, 0, 0, 0],
         [3, 0, 1, 0, 1]], np.uint8)
    gray.dilation(image, out=out_array)
    assert_array_equal(out_array_big, expected_dilation)
    gray.erosion(image, out=out_array)
    assert_array_equal(out_array_big, expected_erosion)
Example #2
0
def test_footprint_overflow():
    footprint = np.ones((17, 17), dtype=np.uint8)
    img = np.zeros((20, 20), dtype=bool)
    img[2:19, 2:19] = True
    binary_res = binary.binary_erosion(img, footprint)
    gray_res = img_as_bool(gray.erosion(img, footprint))
    assert_array_equal(binary_res, gray_res)
Example #3
0
def test_uint16():
    im16, eroded16, dilated16, opened16, closed16 = (map(
        img_as_uint, [im, eroded, dilated, opened, closed]))
    assert_allclose(gray.erosion(im16), eroded16)
    assert_allclose(gray.dilation(im16), dilated16)
    assert_allclose(gray.opening(im16), opened16)
    assert_allclose(gray.closing(im16), closed16)
def test_selem_overflow():
    strel = np.ones((17, 17), dtype=np.uint8)
    img = np.zeros((20, 20), dtype=bool)
    img[2:19, 2:19] = True
    binary_res = binary.binary_erosion(img, strel)
    gray_res = img_as_bool(gray.erosion(img, strel))
    testing.assert_array_equal(binary_res, gray_res)
    def test_compare_with_gray_erosion(self):
        # compare the result of maximum filter with erode

        image = (np.random.rand(100, 100) * 256).astype(np.uint8)
        out = np.empty_like(image)
        mask = np.ones(image.shape, dtype=np.uint8)

        for r in range(3, 20, 2):
            elem = np.ones((r, r), dtype=np.uint8)
            rank.minimum(image=image, selem=elem, out=out, mask=mask)
            cm = gray.erosion(image=image, selem=elem)
            assert_equal(out, cm)
Example #6
0
 def test_dilate_erode_symmetry(self):
     for s in self.footprints:
         c = gray.erosion(self.black_pixel, s)
         d = gray.dilation(self.white_pixel, s)
         assert np.all(c == (255 - d))
Example #7
0
def test_1d_erosion():
    image = np.array([1, 2, 3, 2, 1])
    expected = np.array([1, 1, 2, 1, 1])
    eroded = gray.erosion(image)
    assert_array_equal(eroded, expected)
Example #8
0
def test_float():
    assert_allclose(gray.erosion(im), eroded)
    assert_allclose(gray.dilation(im), dilated)
    assert_allclose(gray.opening(im), opened)
    assert_allclose(gray.closing(im), closed)
def test_binary_erosion():
    strel = selem.square(3)
    binary_res = binary.binary_erosion(bw_img, strel)
    gray_res = img_as_bool(gray.erosion(bw_img, strel))
    testing.assert_array_equal(binary_res, gray_res)
def test_non_square_image():
    strel = selem.square(3)
    binary_res = binary.binary_erosion(bw_img[:100, :200], strel)
    gray_res = img_as_bool(gray.erosion(bw_img[:100, :200], strel))
    testing.assert_array_equal(binary_res, gray_res)
Example #11
0
def test_binary_erosion():
    footprint = morphology.square(3)
    binary_res = binary.binary_erosion(bw_img, footprint)
    gray_res = img_as_bool(gray.erosion(bw_img, footprint))
    assert_array_equal(binary_res, gray_res)
Example #12
0
def test_non_square_image():
    footprint = morphology.square(3)
    binary_res = binary.binary_erosion(bw_img[:100, :200], footprint)
    gray_res = img_as_bool(gray.erosion(bw_img[:100, :200], footprint))
    assert_array_equal(binary_res, gray_res)