Ejemplo n.º 1
0
def test_cy_convolve():
    small_domain = np.ones((5, 6, 7), dtype=np.uint64)
    kernel = np.ones((3, 3, 3), dtype=np.uint64)
    kernel = kernel[::-1, ::-1, ::-1]
    points = np.array([[0, 0, 0], [1, 1, 1]], dtype=np.int)

    result = thinning.cy_convolve(small_domain, kernel, points, 'constant', 0)

    nose.tools.assert_equal(len(result), 2)
    np.testing.assert_array_equal(result[0], 8)
    np.testing.assert_array_equal(result[1], 27)
    kernel = rop.DIRECTIONS_LIST[0]
    result = thinning.cy_convolve(small_domain, kernel, points, 'reflect', 0)
    nose.tools.assert_equal(result[0], 2**26 - 1)
    nose.tools.assert_equal(result[1], 2**26 - 1)
Ejemplo n.º 2
0
def test_cy_convolve_bounds():
    small_domain = np.ones((5, 6, 7), dtype=np.uint64)
    kernel = np.ones((3, 3, 3), dtype=np.uint64)
    kernel = kernel[::-1, ::-1, ::-1]
    points = np.array([[0, 0, 0]], dtype=np.int)

    result = thinning.cy_convolve(small_domain, kernel, points, 'reflect', 0)

    nose.tools.assert_equal(len(result), 1)
    np.testing.assert_array_equal(result, 27)
Ejemplo n.º 3
0
def test_cy_convolve_basic():
    small_domain = np.zeros((5, 6, 7), dtype=np.uint64)
    kernel = np.zeros((3, 3, 3), dtype=np.uint64)
    kernel = kernel[::-1, ::-1, ::-1]
    points = np.zeros((2, 3), dtype=np.int)

    result = thinning.cy_convolve(small_domain, kernel, points, 'constant', 0)

    nose.tools.assert_equal(len(result), 2)
    np.testing.assert_array_equal(result, 0)
Ejemplo n.º 4
0
def test_cy_convole_vs_scipy():
    small_domain = np.random.randint(10, size=(5, 6, 7), dtype=np.uint64)
    kernel = np.random.randint(2, size=(3, 3, 3), dtype=np.uint64)
    kernel_flipped = kernel[::-1, ::-1, ::-1]
    np_result = sci_filter.convolve(small_domain, kernel)
    points = np.array([[1, 2, 3], [0, 0, 0]], dtype=np.int)

    result = thinning.cy_convolve(small_domain, kernel_flipped, points,
                                  'reflect', 0)

    nose.tools.assert_equal(result[0], np_result[1, 2, 3])
    nose.tools.assert_equal(result[1], np_result[0, 0, 0])
Ejemplo n.º 5
0
def test_cy_convolve_harder():
    cylinder_radius = 5
    shape = (32, 32, 32)
    axis = 0
    cylinder_in_axis = vessel_phantom.cylinder_on_axis(radius=cylinder_radius,
                                                       axis=axis,
                                                       shape=shape)
    cylinder_in_axis = (cylinder_in_axis / 255).astype(np.uint64)
    points = np.array([[31, 12, 15]], dtype=np.int)
    kernel = np.asarray(rop.DIRECTIONS_LIST[0])[tuple([slice(None, None, -1)] *
                                                      3)]
    cylinder_skeleton = thinning.cy_convolve(cylinder_in_axis, kernel, points,
                                             'reflect', 0)
    # after convolving the reference array
    # sum should be less than 2 ** 26 -1 (if all the 1st ordered neighborhood is 1)
    nose.tools.assert_less_equal(cylinder_skeleton.sum(), 2**26 - 1)