recon_surf.sample_parc

recon_surf.sample_parc.construct_adj_cluster(tria, annot)[source]

Compute adjacency matrix of edges from same annotation label only.

Operates only on triangles and removes edges that cross annotation label boundaries.

Returns:
csc_matrix

The non-directed adjacency matrix will be symmetric. Each inner edge (i,j) will have the number of triangles that contain this edge. Inner edges usually 2, boundary edges 1. Higher numbers can occur when there are non-manifold triangles. The sparse matrix can be binarized via: adj.data = np.ones(adj.data.shape).

recon_surf.sample_parc.find_all_islands(surf, annot)[source]

Find vertices in disconnected islands for all labels in surface annotation.

Parameters:
surftuple

Surface as returned by nibabel fs.read_geometry, where: surf[0] is the np.array of (n, 3) vertex coordinates and surf[1] is the np.array of (m, 3) triangle indices.

annotnp.ndarray

Annotation as an int array of (n,) with label ids for each vertex. This is for example the first element of the tupel returned by nibabel fs.read_annot.

Returns:
vidxnp.ndarray (i,)

Arrray listing vertex indices of island vertices, empty if no islands (components disconnetcted from largest label region) are found.

recon_surf.sample_parc.options_parse()[source]

Create a command line interface and return command line options.

Returns:
optionsargparse.Namespace

Namespace object holding options.

recon_surf.sample_parc.replace_labels(img_labels, img_lut, surf_lut)[source]

Replace image labels with corresponding surface labels or unknown.

Parameters:
img_labelsnp.ndarray(n,)

Array with imgage label ids.

img_lutstr

Filename for image label look up table.

surf_lutstr

Filename for surface label look up table.

Returns:
surf_labelsnp.ndarray (n,)

Array with surface label ids.

surf_ctabnp.ndarray shape(m,4)

Surface color table (RGBA).

surf_namesnp.ndarray[str] shape(m,)

Names of label regions.

recon_surf.sample_parc.sample_img(surf, img, cortex=None, projmm=0.0, radius=None)[source]

Sample volume at a distance from the surface.

Parameters:
surftuple | str

Surface as returned by nibabel fs.read_geometry, where: surf[0] is the np.array of (n, 3) vertex coordinates and surf[1] is the np.array of (m, 3) triangle indices. If type is str, read surface from file.

imgnibabel.image | str

Image to sample. If type is str, read image from file.

cortexnp.ndarray | str

Filename of cortex label or np.array with cortex indices.

projmmfloat

Sample projmm mm along the surface vertex normals (default=0).

radiusfloat, optional

If given and if the sample is equal to zero, then consider all voxels inside this radius to find a non-zero value.

Returns:
samplesnp.ndarray (n,)

Sampled values.

recon_surf.sample_parc.sample_nearest_nonzero(img, vox_coords, radius=3.0)[source]

Sample closest non-zero value in a ball of radius around vox_coords.

Parameters:
imgnibabel.image

Image to sample. Voxels need to be isotropic.

vox_coordsndarray float shape(n,3)

Coordinates in voxel space around which to search.

radiusfloat default 3.0

Consider all voxels inside this radius to find a non-zero value.

Returns:
samplesnp.ndarray(n,)

Sampled values, returns zero for vertices where values are zero in ball.

recon_surf.sample_parc.sample_parc(surf, seg, imglut, surflut, outaparc, cortex=None, projmm=0.0, radius=None)[source]

Sample cortical GM labels from image to surface and smooth.

Parameters:
surftuple | str

Surface as returned by nibabel fs.read_geometry, where: surf[0] is the np.array of (n, 3) vertex coordinates and surf[1] is the np.array of (m, 3) triangle indices. If type is str, read surface from file.

segnibabel.image | str

Image to sample. If type is str, read image from file.

imglutstr

Filename for image label look up table.

surflutstr

Filename for surface label look up table.

outaparcstr

Filename for output surface parcellation.

cortexnp.ndarray | str

Filename of cortex label or np.ndarray with cortex indices.

projmmfloat

Sample projmm mm along the surface vertex normals (default=0).

radiusfloat, optional

If given and if the sample is equal to zero, then consider all voxels inside this radius to find a non-zero value.