conn_comp,NeuroSurfaceVector-method | R Documentation |
This method identifies connected components on a NeuroSurface object based on a given threshold.
## S4 method for signature 'NeuroSurfaceVector'
conn_comp(x, threshold, index = 1)
## S4 method for signature 'NeuroSurface'
conn_comp(x, threshold)
x |
A |
threshold |
A numeric vector of length 2 specifying the lower and upper thresholds for including vertices in the components. |
index |
the index/column of the underlying data matrix to cluster |
This method computes connected components on the surface by:
Thresholding the surface data using the provided threshold values.
Creating a subgraph of the surface mesh containing only the vertices that pass the threshold.
Identifying connected components in this subgraph.
Assigning component indices and sizes to the original vertices.
Vertices that do not pass the threshold are assigned a value of 0 in both output surfaces.
A list containing two NeuroSurface
objects:
index |
A |
size |
A |
NeuroSurface
, components
# Load a sample surface from the package
surf_file <- system.file("extdata", "std.8.lh.inflated.asc", package = "neurosurf")
surf_geom <- readAsc(surf_file)
# Create random data for the surface with some clusters
n_vertices <- nrow(coords(surf_geom))
set.seed(123)
random_data <- rnorm(n_vertices, mean = 0, sd = 1)
# Create a few clusters of higher values
cluster_centers <- sample(1:n_vertices, 5)
g <- graph(surf_geom)
# For each cluster center, set nearby vertices to higher values
for (center in cluster_centers) {
# Get neighbors within 2 steps
neighbors <- unlist(igraph::neighborhood(g, 2, center))
random_data[neighbors] <- random_data[neighbors] + 2
}
# Create a NeuroSurface object
neuro_surf <- NeuroSurface(geometry = surf_geom,
indices = 1:n_vertices,
data = random_data)
# Find connected components with threshold c(-Inf, 1.5)
# This will identify clusters where values are >= 1.5
components <- conn_comp(neuro_surf, c(-Inf, 1.5))
# Check the number of components found
max(series(components$index))
# Check the size of the largest component
max(series(components$size))
# Count vertices in components of size >= 10
sum(series(components$size) >= 10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.