Beispiel #1
0
def test_discontiguous_out_array():
    # fmt: off
    image = cp.asarray([[5, 6, 2], [7, 2, 2], [3, 5, 1]], cp.uint8)
    # fmt: on
    out_array_big = cp.zeros((5, 5), cp.uint8)
    out_array = out_array_big[::2, ::2]
    expected_dilation = cp.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],
        ],
        cp.uint8,
    )
    expected_erosion = cp.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],
        ],
        cp.uint8,
    )
    grey.dilation(image, out=out_array)
    cp.testing.assert_array_equal(out_array_big, expected_dilation)
    grey.erosion(image, out=out_array)
    cp.testing.assert_array_equal(out_array_big, expected_erosion)
Beispiel #2
0
def test_uint16():
    im16, eroded16, dilated16, opened16, closed16 = map(
        img_as_uint, [im, eroded, dilated, opened, closed])
    cp.testing.assert_allclose(grey.erosion(im16), eroded16)
    cp.testing.assert_allclose(grey.dilation(im16), dilated16)
    cp.testing.assert_allclose(grey.opening(im16), opened16)
    cp.testing.assert_allclose(grey.closing(im16), closed16)
Beispiel #3
0
def test_selem_overflow():
    strel = cp.ones((17, 17), dtype=cp.uint8)
    img = cp.zeros((20, 20), dtype=bool)
    img[2:19, 2:19] = True
    binary_res = binary.binary_erosion(img, strel)
    grey_res = img_as_bool(grey.erosion(img, strel))
    testing.assert_array_equal(binary_res, grey_res)
Beispiel #4
0
 def test_dilate_erode_symmetry(self):
     for s in self.selems:
         c = grey.erosion(self.black_pixel, s)
         d = grey.dilation(self.white_pixel, s)
         assert cp.all(c == (255 - d))
Beispiel #5
0
def test_1d_erosion():
    image = cp.array([1, 2, 3, 2, 1])
    expected = cp.array([1, 1, 2, 1, 1])
    eroded = grey.erosion(image)
    cp.testing.assert_array_equal(eroded, expected)
Beispiel #6
0
def test_float():
    cp.testing.assert_allclose(grey.erosion(im), eroded)
    cp.testing.assert_allclose(grey.dilation(im), dilated)
    cp.testing.assert_allclose(grey.opening(im), opened)
    cp.testing.assert_allclose(grey.closing(im), closed)
Beispiel #7
0
def test_binary_erosion():
    strel = selem.square(3)
    binary_res = binary.binary_erosion(bw_img, strel)
    grey_res = img_as_bool(grey.erosion(bw_img, strel))
    testing.assert_array_equal(binary_res, grey_res)
Beispiel #8
0
def test_non_square_image():
    strel = selem.square(3)
    binary_res = binary.binary_erosion(bw_img[:100, :200], strel)
    grey_res = img_as_bool(grey.erosion(bw_img[:100, :200], strel))
    testing.assert_array_equal(binary_res, grey_res)