Пример #1
0
def test_morphsnakes_black():
    img = cp.zeros((11, 11))
    ls = disk_level_set(img.shape, (5, 5), 3)

    ref_zeros = cp.zeros(img.shape, dtype=cp.int8)
    ref_ones = cp.ones(img.shape, dtype=cp.int8)

    acwe_ls = morphological_chan_vese(img, iterations=6, init_level_set=ls)
    assert_array_equal(acwe_ls, ref_zeros)

    gac_ls = morphological_geodesic_active_contour(img,
                                                   iterations=6,
                                                   init_level_set=ls)
    assert_array_equal(gac_ls, ref_zeros)

    gac_ls2 = morphological_geodesic_active_contour(
        img,
        iterations=6,
        init_level_set=ls,
        balloon=1,
        threshold=-1,
        smoothing=0,
    )
    assert_array_equal(gac_ls2, ref_ones)

    assert acwe_ls.dtype == gac_ls.dtype == gac_ls2.dtype == cp.int8
Пример #2
0
def test_morphsnakes_incorrect_ndim():
    img = cp.zeros((4, 4, 4, 4))
    ls = cp.zeros((4, 4, 4, 4))

    with pytest.raises(ValueError):
        morphological_chan_vese(img, iterations=1, init_level_set=ls)
    with pytest.raises(ValueError):
        morphological_geodesic_active_contour(img,
                                              iterations=1,
                                              init_level_set=ls)
Пример #3
0
def test_morphsnakes_simple_shape_geodesic_active_contour():
    img = disk_level_set((11, 11), center=(5, 5), radius=3.5).astype(float)
    gimg = inverse_gaussian_gradient(img, alpha=10.0, sigma=1.0)
    ls = disk_level_set(img.shape, center=(5, 5), radius=6)

    ref = cp.asarray(
        [
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
            [0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0],
            [0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
            [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        ],
        dtype=cp.int8,
    )

    gac_ls = morphological_geodesic_active_contour(gimg,
                                                   iterations=10,
                                                   init_level_set=ls,
                                                   balloon=-1)
    assert_array_equal(gac_ls, ref)
    assert gac_ls.dtype == cp.int8
Пример #4
0
def test_init_level_sets():
    image = cp.zeros((6, 6))
    checkerboard_ls = morphological_chan_vese(image, 0, "checkerboard")
    checkerboard_ref = cp.asarray(
        [
            [0, 0, 0, 0, 0, 1],
            [0, 0, 0, 0, 0, 1],
            [0, 0, 0, 0, 0, 1],
            [0, 0, 0, 0, 0, 1],
            [0, 0, 0, 0, 0, 1],
            [1, 1, 1, 1, 1, 0],
        ],
        dtype=cp.int8,
    )

    disk_ls = morphological_geodesic_active_contour(image, 0, "disk")
    disk_ref = cp.asarray(
        [
            [0, 0, 0, 0, 0, 0],
            [0, 0, 1, 1, 1, 0],
            [0, 1, 1, 1, 1, 1],
            [0, 1, 1, 1, 1, 1],
            [0, 1, 1, 1, 1, 1],
            [0, 0, 1, 1, 1, 0],
        ],
        dtype=cp.int8,
    )

    assert_array_equal(checkerboard_ls, checkerboard_ref)
    assert_array_equal(disk_ls, disk_ref)