예제 #1
0
def test_binary_output_3d():
    image = cp.zeros((9, 9, 9), cp.uint16)
    image[2:-2, 2:-2, 2:-2] = 2 ** 14
    image[3:-3, 3:-3, 3:-3] = 2 ** 15
    image[4, 4, 4] = 2 ** 16 - 1

    bin_opened = binary.binary_opening(image)
    bin_closed = binary.binary_closing(image)

    int_opened = cp.empty_like(image, dtype=cp.uint8)
    int_closed = cp.empty_like(image, dtype=cp.uint8)
    binary.binary_opening(image, out=int_opened)
    binary.binary_closing(image, out=int_closed)

    np.testing.assert_equal(bin_opened.dtype, cp.bool_)
    np.testing.assert_equal(bin_closed.dtype, cp.bool_)

    np.testing.assert_equal(int_opened.dtype, cp.uint8)
    np.testing.assert_equal(int_closed.dtype, cp.uint8)
예제 #2
0
def test_3d_fallback_default_selem():
    # 3x3x3 cube inside a 7x7x7 image:
    image = cp.zeros((7, 7, 7), cp.bool_)
    image[2:-2, 2:-2, 2:-2] = 1

    opened = binary.binary_opening(image)

    # expect a "hyper-cross" centered in the 5x5x5:
    image_expected = cp.zeros((7, 7, 7), dtype=bool)
    image_expected[2:5, 2:5, 2:5] = ndi.generate_binary_structure(3, 1)
    testing.assert_array_equal(opened, image_expected)
예제 #3
0
def test_2d_ndimage_equivalence():
    image = cp.zeros((9, 9), cp.uint16)
    image[2:-2, 2:-2] = 2 ** 14
    image[3:-3, 3:-3] = 2 ** 15
    image[4, 4] = 2 ** 16 - 1

    bin_opened = binary.binary_opening(image)
    bin_closed = binary.binary_closing(image)

    selem = ndi.generate_binary_structure(2, 1)
    ndimage_opened = ndi.binary_opening(image, structure=selem)
    ndimage_closed = ndi.binary_closing(image, structure=selem)

    testing.assert_array_equal(bin_opened, ndimage_opened)
    testing.assert_array_equal(bin_closed, ndimage_closed)
예제 #4
0
def test_binary_opening():
    strel = selem.square(3)
    binary_res = binary.binary_opening(bw_img, strel)
    grey_res = img_as_bool(grey.opening(bw_img, strel))
    testing.assert_array_equal(binary_res, grey_res)