1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
"""
==================================
BUAN Bundle Shape Similarity Score
==================================
This example explains how we can use BUAN :footcite:p:`Chandio2020a` 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.
cb_subj1, _ = two_cingulum_bundles()
###############################################################################
# Let's create two streamline sets (bundles) from same bundle cb_subj1 by
# randomly selecting 60 streamlines two times.
rng = np.random.default_rng()
bundle1 = select_random_set_of_streamlines(cb_subj1, 60, rng=None)
bundle2 = select_random_set_of_streamlines(cb_subj1, 60, rng=None)
###############################################################################
# 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",
)
###############################################################################
# .. rst-class:: centered small fst-italic fw-semibold
#
# 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.
threshold = 5
ba_score = bundle_shape_similarity(
bundle1, bundle2, rng, clust_thr=clust_thr, threshold=threshold
)
print("Shape similarity score = ", ba_score)
###############################################################################
# Let's change the value of threshold to 10.
threshold = 10
ba_score = bundle_shape_similarity(
bundle1, bundle2, rng, clust_thr=clust_thr, threshold=threshold
)
print("Shape similarity score = ", ba_score)
###############################################################################
# Higher value of threshold gives us higher shape similarity score as it is
# more lenient.
#
#
#
# References
# ----------
#
# .. footbibliography::
#
|