예제 #1
0
def test_3d_energy_decrease():

    a_black = cp.zeros((5, 5, 5)).astype(np.uint8)
    a_black[2, 2, 2] = 255
    a_white = invert(a_black)

    assert_array_less(
        meijering(a_black, black_ridges=True).std(), a_black.std()
    )
    assert_array_less(
        meijering(a_white, black_ridges=False).std(), a_white.std()
    )

    assert_array_less(
        sato(a_black, black_ridges=True, mode="reflect").std(), a_black.std()
    )
    assert_array_less(
        sato(a_white, black_ridges=False, mode="reflect").std(), a_white.std()
    )

    assert_array_less(frangi(a_black, black_ridges=True).std(), a_black.std())
    assert_array_less(frangi(a_white, black_ridges=False).std(), a_white.std())

    assert_array_less(
        hessian(a_black, black_ridges=True, mode="reflect").std(), a_black.std()
    )
    assert_array_less(
        hessian(a_white, black_ridges=False, mode="reflect").std(),
        a_white.std(),
    )
예제 #2
0
def test_3d_cropped_camera_image():

    a_black = crop(cp.asarray(camera()), ((206, 206), (206, 206)))
    a_black = cp.dstack([a_black, a_black, a_black])
    a_white = invert(a_black)

    zeros = cp.zeros((100, 100, 3))
    ones = cp.ones((100, 100, 3))

    assert_allclose(
        meijering(a_black, black_ridges=True),
        meijering(a_white, black_ridges=False),
    )

    assert_allclose(
        sato(a_black, black_ridges=True, mode="reflect"),
        sato(a_white, black_ridges=False, mode="reflect"),
    )

    assert_allclose(frangi(a_black, black_ridges=True), zeros, atol=1e-3)
    assert_allclose(frangi(a_white, black_ridges=False), zeros, atol=1e-3)

    assert_allclose(
        hessian(a_black, black_ridges=True, mode="reflect"), ones, atol=1 - 1e-7
    )
    assert_allclose(
        hessian(a_white, black_ridges=False, mode="reflect"),
        ones,
        atol=1 - 1e-7,
    )
예제 #3
0
def test_invert_bool():
    dtype = "bool"
    image = cp.zeros((3, 3), dtype=dtype)
    upper_dtype_limit = dtype_limits(image, clip_negative=False)[1]
    image[1, :] = upper_dtype_limit
    expected = cp.zeros((3, 3), dtype=dtype) + upper_dtype_limit
    expected[1, :] = 0
    result = invert(image)
    assert_array_equal(expected, result)
예제 #4
0
def test_invert_float64_unsigned():
    dtype = "float64"
    image = cp.zeros((3, 3), dtype=dtype)
    lower_dtype_limit, upper_dtype_limit = dtype_limits(
        image, clip_negative=True
    )
    image[2, :] = upper_dtype_limit
    expected = cp.zeros((3, 3), dtype=dtype)
    expected[0, :] = upper_dtype_limit
    expected[1, :] = upper_dtype_limit
    result = invert(image)
    assert_array_equal(expected, result)
예제 #5
0
def test_invert_int8():
    dtype = "int8"
    image = cp.zeros((3, 3), dtype=dtype)
    lower_dtype_limit, upper_dtype_limit = dtype_limits(
        image, clip_negative=False
    )
    image[1, :] = lower_dtype_limit
    image[2, :] = upper_dtype_limit
    expected = cp.zeros((3, 3), dtype=dtype)
    expected[2, :] = lower_dtype_limit
    expected[1, :] = upper_dtype_limit
    expected[0, :] = -1
    result = invert(image)
    assert_array_equal(expected, result)
예제 #6
0
def test_3d_linearity():

    a_black = cp.ones((3, 3, 3)).astype(np.uint8)
    a_white = invert(a_black)

    assert_allclose(
        meijering(1 * a_black, black_ridges=True),
        meijering(10 * a_black, black_ridges=True),
        atol=1e-3,
    )
    assert_allclose(
        meijering(1 * a_white, black_ridges=False),
        meijering(10 * a_white, black_ridges=False),
        atol=1e-3,
    )

    assert_allclose(
        sato(1 * a_black, black_ridges=True, mode="reflect"),
        sato(10 * a_black, black_ridges=True, mode="reflect"),
        atol=1e-3,
    )
    assert_allclose(
        sato(1 * a_white, black_ridges=False, mode="reflect"),
        sato(10 * a_white, black_ridges=False, mode="reflect"),
        atol=1e-3,
    )

    assert_allclose(
        frangi(1 * a_black, black_ridges=True),
        frangi(10 * a_black, black_ridges=True),
        atol=1e-3,
    )
    assert_allclose(
        frangi(1 * a_white, black_ridges=False),
        frangi(10 * a_white, black_ridges=False),
        atol=1e-3,
    )

    assert_allclose(
        hessian(1 * a_black, black_ridges=True, mode="reflect"),
        hessian(10 * a_black, black_ridges=True, mode="reflect"),
        atol=1e-3,
    )
    assert_allclose(
        hessian(1 * a_white, black_ridges=False, mode="reflect"),
        hessian(10 * a_white, black_ridges=False, mode="reflect"),
        atol=1e-3,
    )
예제 #7
0
def test_3d_null_matrix():

    a_black = cp.zeros((3, 3, 3)).astype(cp.uint8)
    a_white = invert(a_black)

    zeros = cp.zeros((3, 3, 3))
    ones = cp.ones((3, 3, 3))

    assert_allclose(meijering(a_black, black_ridges=True), zeros, atol=1e-1)
    assert_allclose(meijering(a_white, black_ridges=False), zeros, atol=1e-1)

    assert_array_equal(sato(a_black, black_ridges=True, mode="reflect"), zeros)
    assert_array_equal(sato(a_white, black_ridges=False, mode="reflect"), zeros)

    assert_allclose(frangi(a_black, black_ridges=True), zeros, atol=1e-3)
    assert_allclose(frangi(a_white, black_ridges=False), zeros, atol=1e-3)

    assert_array_equal(
        hessian(a_black, black_ridges=False, mode="reflect"), ones
    )
    assert_array_equal(
        hessian(a_white, black_ridges=True, mode="reflect"), ones
    )
예제 #8
0
def test_invert_roundtrip():
    for t, limits in dtype_range.items():
        image = cp.array(limits, dtype=t)
        expected = invert(invert(image))
        assert_array_equal(image, expected)