brainspace.mesh.mesh_operations.get_connected_components¶
-
brainspace.mesh.mesh_operations.
get_connected_components
(surf, labeling=None, mask=None, fill=0, append=False, key='components')[source]¶ Get connected components.
Connected components are based on connectivity (and same label if labeling is provided).
Parameters: - surf (vtkPolyData or BSPolyData) – Input surface.
- labeling (str or 1D ndarray, optional) – Array with labels. If str, it must be in the point data attributes of surf. Default is None. If provided, connectivity is based on neighboring points with the same label.
- mask (str or 1D ndarray, optional) – Boolean mask. If str, it must be in the point data attributes of surf. Default is None. If specified, only consider points within the mask.
- fill (int or float, optional) – Value used for entries out of the mask. Only used if the target_mask is provided. Default is 0.
- append (bool, optional) – If True, append array to point data attributes of input surface and return surface. Otherwise, only return array. Default is False.
- key (str, optional) – Array name to append to surface’s point data attributes. Only used if
append == True
. Default is ‘components’.
Returns: output (vtkPolyData, BSPolyData or ndarray) – 1D array with different labels for each connected component. Return ndarray if
append == False
. Otherwise, return input surface with the new array.Notes
VTK point data does not accept boolean arrays. If the mask is provided as a string, the mask is built from the corresponding array such that any value larger than 0 is True.