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
in the clustering framework.* """ from dipy.segment.clustering import QuickBundles from dipy.segment.metric import IdentityFeature from dipy.segment.metric import AveragePointwiseEuclideanMetric # Get some streamlines. streamlines = get_streamlines() # Previously defined. # Make sure our streamlines have the same number of points. from dipy.tracking.streamline import set_number_of_points streamlines = set_number_of_points(streamlines, nb_points=12) # Create an instance of `IdentityFeature` and tell metric to use it. feature = IdentityFeature() metric = AveragePointwiseEuclideanMetric(feature=feature) qb = QuickBundles(threshold=10., metric=metric) clusters = qb.cluster(streamlines) print("Nb. clusters:", len(clusters)) print("Cluster sizes:", list(map(len, clusters))) """ :: Nb. clusters: 4 Cluster sizes: [64, 191, 47, 1]
#%% 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: