[5d12a0]: / ants / segmentation / kelly_kapowski.py

Download this file

92 lines (66 with data), 2.4 kB

 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
"""
Kelly Kapowski algorithm with computing cortical thickness
"""
__all__ = ['kelly_kapowski']
import ants
from ants.internal import get_lib_fn, get_pointer_string, process_arguments
def kelly_kapowski(s, g, w, its=45, r=0.025, m=1.5, gm_label=2, wm_label=3, **kwargs):
"""
Compute cortical thickness using the DiReCT algorithm.
Diffeomorphic registration-based cortical thickness based on probabilistic
segmentation of an image. This is an optimization algorithm.
Arguments
---------
s : ANTsimage
segmentation image
g : ANTsImage
gray matter probability image
w : ANTsImage
white matter probability image
its : integer
convergence params - controls iterations
r : scalar
gradient descent update parameter
m : scalar
gradient field smoothing parameter
gm_label : integer
label for gray matter in the segmentation image
wm_label : integer
label for white matter in the segmentation image
kwargs : keyword arguments
anything else, see KellyKapowski help in ANTs
Returns
-------
ANTsImage
Example
-------
>>> import ants
>>> img = ants.image_read( ants.get_ants_data('r16') ,2)
>>> img = ants.resample_image(img, (64,64),1,0)
>>> mask = ants.get_mask( img )
>>> segs = ants.kmeans_segmentation( img, k=3, kmask = mask)
>>> thick = ants.kelly_kapowski(s=segs['segmentation'], g=segs['probabilityimages'][1],
w=segs['probabilityimages'][2], its=45,
r=0.5, m=1)
"""
if ants.is_image(s):
s = s.clone('unsigned int')
d = s.dimension
outimg = g.clone() * 0.0
kellargs = {'d': d,
's': "[{},{},{}]".format(get_pointer_string(s),gm_label,wm_label),
'g': g,
'w': w,
'c': "[{}]".format(its),
'r': r,
'm': m,
'o': outimg}
for k, v in kwargs.items():
kellargs[k] = v
processed_kellargs = process_arguments(kellargs)
libfn = get_lib_fn('KellyKapowski')
libfn(processed_kellargs)
# Check thickness is not still all zeros
if outimg.sum() == 0.0:
raise RuntimeError("KellyKapowski failed to compute thickness")
return outimg