def isolated(XYZ, k=18): """ Outputs an index I of isolated points from their integer coordinates, XYZ (3, n), and under k-connectivity, k = 6, 18 or 24. """ A, B, D = FG.graph_3d_grid(XYZ.transpose(),k) # Number of vertices V = max(A) + 1 # Labels of connected components label = FG.graph_cc(A,B,D,V) # Isolated points ncc = label.max() + 1 p = XYZ.shape[1] size = np.zeros(ncc, float) ones = np.ones((p, 1), float) add_lines(ones, size.reshape(ncc, 1), label) return np.where(size[label] == 1)[0]
def extract_clusters_from_thresh(T,XYZ,th,k=18): """ Extract clusters from statistical map above specified threshold In: T (p) statistical map XYZ (3,p) voxels coordinates th <float> threshold k <int> the number of neighbours considered. (6,18 or 26) Out: labels (p) cluster labels """ labels = -np.ones(len(T),int) I = np.where(T >= th)[0] if len(I)>0: SupraThreshXYZ = XYZ[:, I] # Compute graph associated to suprathresh_coords A, B, D = graph_3d_grid(SupraThreshXYZ.transpose(),k) # Number of vertices V = max(A) + 1 # Labels of connected components CC_label = graph_cc(A,B,D,V) labels[I] = CC_label return labels