Note
Go to the end to download the full example code.
BUAN Bundle Shape Similarity Score#
This example explains how we can use BUAN [1] to calculate shape similarity between two given bundles. Where, shape similarity score of 1 means two bundles are extremely close in shape and 0 implies no shape similarity whatsoever.
Shape similarity score can be used to compare populations or individuals. It can also serve as a quality assurance metric, to validate streamline registration quality, bundle extraction quality by calculating output with a reference bundle or other issues with pre-processing by calculating shape dissimilarity with a reference bundle.
First import the necessary modules.
import numpy as np
from dipy.data import two_cingulum_bundles
from dipy.segment.bundles import (
    bundle_shape_similarity,
    select_random_set_of_streamlines,
)
from dipy.viz import actor, window
To show the concept we will use two pre-saved cingulum bundle. Let’s start by fetching the data.
Let’s create two streamline sets (bundles) from same bundle cb_subj1 by randomly selecting 60 streamlines two times.
Now, let’s visualize two bundles.
def show_both_bundles(bundles, colors=None, show=True, fname=None):
    scene = window.Scene()
    scene.SetBackground(1.0, 1, 1)
    for i, bundle in enumerate(bundles):
        color = colors[i]
        streamtube_actor = actor.streamtube(bundle, colors=color, linewidth=0.3)
        streamtube_actor.RotateX(-90)
        streamtube_actor.RotateZ(90)
        scene.add(streamtube_actor)
    if show:
        window.show(scene)
    if fname is not None:
        window.record(scene=scene, n_frames=1, out_path=fname, size=(900, 900))
show_both_bundles(
    [bundle1, bundle2],
    colors=[(1, 0, 0), (0, 1, 0)],
    show=False,
    fname="two_bundles.png",
)

Two Cingulum Bundles.
Calculate shape similarity score between two bundles. 0 cluster_thr because we want to use all streamlines and not the centroids of clusters.
clust_thr = [0]
Threshold indicates how strictly we want two bundles to be similar in shape.
Shape similarity score =  0.6
Let’s change the value of threshold to 10.
Shape similarity score =  0.9416666666666667
Higher value of threshold gives us higher shape similarity score as it is more lenient.
References#
Total running time of the script: (0 minutes 0.614 seconds)