File: bundle_group_registration.py

package info (click to toggle)
dipy 1.11.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,144 kB
  • sloc: python: 92,240; makefile: 272; pascal: 183; sh: 162; ansic: 106
file content (113 lines) | stat: -rw-r--r-- 3,407 bytes parent folder | download | duplicates (2)
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
113
"""
=============================
Groupwise Bundle Registration
=============================

This example explains how to coregister a set of bundles to a common space that
is not biased by any specific bundle. This is useful when we want to align all
the bundles but do not have a target reference space defined by an atlas
:footcite:p:`RomeroBascones2022`.

How it works
============

The bundle groupwise registration framework in DIPY relies on streamline linear
registration (SLR) :footcite:p:`Garyfallidis2015` and an iterative process.

In each iteration, bundles are shuffled and matched in pairs. Then, each pair
of bundles are simultaneously moved to a common space in between both.

After all pairs have been aligned, a group distance metric is computed as the
mean pairwise distance between all bundle pairs. With each iteration, bundles
get closer to each other and the group distance decreases.

When the reduction in the group distance reaches a tolerance level the process
ends.

To reduce computational time, by default both registration and distance
computation are performed on streamline centroids (obtained with Quickbundles)
:footcite:p:`Garyfallidis2012a`.

Example
=======

We start by importing and creating the necessary functions:
"""

import logging

from dipy.align.streamlinear import groupwise_slr
from dipy.data import read_five_af_bundles
from dipy.viz.streamline import show_bundles

logging.basicConfig(level=logging.INFO)

###############################################################################
# To run groupwise registration we need to have our input bundles stored in a
# list.
#
# Here we load 5 left arcuate fasciculi and store them in a list.

bundles = read_five_af_bundles()

###############################################################################
# Let's now visualize our input bundles:

colors = [
    [0.91, 0.26, 0.35],
    [0.99, 0.50, 0.38],
    [0.99, 0.88, 0.57],
    [0.69, 0.85, 0.64],
    [0.51, 0.51, 0.63],
]

show_bundles(
    bundles, interactive=False, colors=colors, save_as="before_group_registration.png"
)

###############################################################################
# .. rst-class:: centered small fst-italic fw-semibold
#
# Bundles before registration.
#
#
# They are in native space and, therefore, not aligned.
#
# Now running groupwise registration is as simple as:

bundles_reg, aff, d = groupwise_slr(bundles, verbose=True)

###############################################################################
# Finally, we visualize the registered bundles to confirm that they are now in
# a common space:

show_bundles(
    bundles_reg,
    interactive=False,
    colors=colors,
    save_as="after_group_registration.png",
)

###############################################################################
# .. rst-class:: centered small fst-italic fw-semibold
#
# Bundles after registration.
#
#
#
# Extended capabilities
# =====================
#
# In addition to the registered bundles, `groupwise_slr` also returns a list
# with the individual transformation matrices as well as the pairwise distances
# computed in each iteration.
#
# By changing the input arguments the user can modify the transformation (up to
# affine), the number of maximum number of streamlines per bundle, the level of
# clustering, or the tolerance of the method.
#
# References
# ----------
#
# .. footbibliography::
#