示例#1
0
def test_structure_tensor_eigenvalues_3d():
    image = np.pad(cube(9), 5, mode='constant') * 1000
    boundary = (np.pad(cube(9), 5, mode='constant') -
                np.pad(cube(7), 6, mode='constant')).astype(bool)
    A_elems = structure_tensor(image, sigma=0.1)
    e0, e1, e2 = structure_tensor_eigenvalues(A_elems)
    # e0 should detect facets
    assert np.all(e0[boundary] != 0)
示例#2
0
def test_structure_tensor_eigenvalues():
    square = np.zeros((5, 5))
    square[2, 2] = 1
    A_elems = structure_tensor(square, sigma=0.1, order='rc')
    l1, l2 = structure_tensor_eigenvalues(A_elems)
    assert_array_equal(
        l1,
        np.array([[0, 0, 0, 0, 0], [0, 2, 4, 2, 0], [0, 4, 0, 4, 0],
                  [0, 2, 4, 2, 0], [0, 0, 0, 0, 0]]))
    assert_array_equal(
        l2,
        np.array([[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]]))
示例#3
0
def test_structure_tensor_eigenvalues(dtype):
    square = np.zeros((5, 5), dtype=dtype)
    square[2, 2] = 1
    A_elems = structure_tensor(square, sigma=0.1, order='rc')
    l1, l2 = structure_tensor_eigenvalues(A_elems)
    out_dtype = _supported_float_type(dtype)
    assert all(a.dtype == out_dtype for a in (l1, l2))
    assert_array_equal(
        l1,
        np.array([[0, 0, 0, 0, 0], [0, 2, 4, 2, 0], [0, 4, 0, 4, 0],
                  [0, 2, 4, 2, 0], [0, 0, 0, 0, 0]]))
    assert_array_equal(
        l2,
        np.array([[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]]))
示例#4
0
# About the brightest region (i.e., at row ~ 22 and column ~ 17), we can see
# variations (and, hence, strong gradients) over 2 or 3 (resp. 1 or 2) pixels
# across columns (resp. rows). We may thus choose, say, ``sigma = 1.5`` for
# the window
# function. Alternatively, we can pass sigma on a per-axis basis, e.g.,
# ``sigma = (1, 2, 3)``. Note that size 1 sounds reasonable along the first
# (Z, plane) axis, since the latter is of size 8 (13 - 5). Viewing slices in
# the X-Z or Y-Z planes confirms it is reasonable.

sigma = (1, 1.5, 2.5)
A_elems = feature.structure_tensor(sample, sigma=sigma)

#####################################################################
# We can then compute the eigenvalues of the structure tensor.

eigen = feature.structure_tensor_eigenvalues(A_elems)
eigen.shape

#####################################################################
# Where is the largest eigenvalue?

coords = np.unravel_index(eigen.argmax(), eigen.shape)
assert coords[0] == 0  # by definition
coords

#####################################################################
# .. note::
#    The reader may check how robust this result (coordinates
#    ``(plane, row, column) = coords[1:]``) is to varying ``sigma``.
#
# Let us view the spatial distribution of the eigenvalues in the X-Y plane