def qb_metrics_features(streamlines, threshold=10.0, metric=None, max_nb_clusters=np.iinfo('i4').max): """ Enhancing QuickBundles with different metrics and features metric: 'IF', 'RF', 'CoMF', 'MF', 'AF', 'VBEF', None """ if metric == 'IF': feature = IdentityFeature() metric = AveragePointwiseEuclideanMetric(feature=feature) elif metric == 'RF': feature = ResampleFeature(nb_point=24) metric = AveragePointwiseEuclideanMetric(feature=feature) elif metric == 'CoMF': feature = CenterOfMassFeature() metric = EuclideanMetric(feature) elif metric == 'MF': feature = MidpointFeature() metric = EuclideanMetric(feature) elif metric == 'AF': feature = ArcLengthFeature() metric = EuclideanMetric(feature) elif metric == 'VBEF': feature = VectorOfEndpointsFeature() metric = CosineMetric(feature) else: metric = "MDF_12points" qb = QuickBundles(threshold=threshold, metric=metric, max_nb_clusters=max_nb_clusters) clusters = qb.cluster(streamlines) labels = np.array(len(streamlines) * [None]) N_list = [] for i in range(len(clusters)): N_list.append(clusters[i]['N']) data_clusters = [] for i in range(len(clusters)): labels[clusters[i]['indices']] = i + 1 data_clusters.append(streamlines[clusters[i]['indices']]) return labels, data_clusters, N_list
""" import numpy as np from dipy.viz import window, actor, colormap from dipy.segment.clustering import QuickBundles from dipy.segment.metric import CenterOfMassFeature from dipy.segment.metric import EuclideanMetric # Enables/disables interactive visualization interactive = False # Get some streamlines. streamlines = get_streamlines() # Previously defined. feature = CenterOfMassFeature() metric = EuclideanMetric(feature) qb = QuickBundles(threshold=5., metric=metric) clusters = qb.cluster(streamlines) # Extract feature of every streamline. centers = np.asarray(list(map(feature.extract, streamlines))) # Color each center of mass according to the cluster they belong to. colormap = colormap.create_colormap(np.arange(len(clusters))) colormap_full = np.ones((len(streamlines), 3)) for cluster, color in zip(clusters, colormap): colormap_full[cluster.indices] = color # Visualization scene = window.Scene()
#%% Closing kernel = np.ones((12, 12), np.uint8) closed_img = cv2.morphologyEx(crop_img, cv2.MORPH_CLOSE, kernel) plt.figure(2) plt.imshow(cv2.cvtColor(closed_img, cv2.COLOR_BGR2RGB)) #%% Filtering #blurred_img = cv2.medianBlur(closed_img, 5) #plt.imshow(cv2.cvtColor(blurred_frame, cv2.COLOR_BGR2RGB)) #%% closed_img = np.float32(closed_img) #%% vector_feature = IdentityFeature() metric = EuclideanMetric(feature=vector_feature) qb = QuickBundles(threshold=120000, metric=metric) clusters = qb.cluster(closed_img) print("Nb. clusters:", len(clusters)) imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #indices=clusters[1] #A=closed_img[indices,:,:] #%% for j, group in enumerate(clusters): if len(group) > 1: for indx in group.indices: