Menu

Deep learning for NeuroImaging in Python.

Note

This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the gallery for the big picture.

surfify.utils.neighbors(vertices, triangles, depth=1, direct_neighbor=False)[source]ΒΆ

Build mesh vertices neighbors.

This is the base function to build Direct Neighbors (DiNe) kernels.

Parameters:

vertices : array (N, 3)

the icosahedron vertices.

triangles : array (M, 3)

the icosahedron triangles.

depth : int, default 1

depth to stop the neighbors search, only paths of length <= depth are returned.

direct_neighbor : bool, default False

each spherical surface is composed of two types of vertices: 1) 12 vertices with each having only 5 direct neighbors; and 2) the remaining vertices with each having 6 direct neighbors. For those vertices with 6 neighbors, DiNe assigns the index 1 to the center vertex and the indices 2-7 to its neighbors sequentially according to the angle between the vector of center vertex to neighboring vertex and the x-axis in the tangent plane. For the 12 vertices with only 5 neighbors, DiNe assigns the indices both 1 and 2 to the center vertex, and indices 3-7 to the neighbors in the same way as those vertices with 6 neighbors.

Returns:

neighs : dict

a dictionary with vertices row index as keys and a dictionary of neighbors vertices row indexes organized by rings as values.

See also

neighbors_rec

Examples

>>> from surfify.utils import icosahedron, neighbors
>>> import matplotlib.pyplot as plt
>>> from surfify.plotting import plot_trisurf
>>> ico2_verts, ico2_tris = icosahedron(order=2)
>>> neighs = neighbors(ico2_verts, ico2_tris, direct_neighbor=True)
>>> fig, ax = plt.subplots(1, 1, subplot_kw={
        "projection": "3d", "aspect": "auto"}, figsize=(10, 10))
>>> plot_trisurf(ico2_verts, triangles=ico2_tris, colorbar=False, fig=fig,
                 ax=ax)
>>> center = ico2_verts[0]
>>> for cnt, idx in enumerate(neighs[0]):
>>>     point = ico2_verts[idx]
>>>     ax.scatter(point[0], point[1], point[2], marker="o", c="red",
                   s=100)
>>> ax.scatter(center[0], center[1], center[2], marker="o", c="blue",
               s=100)
>>> plt.show()

Follow us

© 2025, nidl developers