|
a |
|
b/ants/ops/weingarten_image_curvature.py |
|
|
1 |
|
|
|
2 |
__all__ = ['weingarten_image_curvature'] |
|
|
3 |
|
|
|
4 |
import numpy as np |
|
|
5 |
|
|
|
6 |
import ants |
|
|
7 |
from ants.decorators import image_method |
|
|
8 |
from ants.internal import get_lib_fn |
|
|
9 |
|
|
|
10 |
@image_method |
|
|
11 |
def weingarten_image_curvature(image, sigma=1.0, opt='mean'): |
|
|
12 |
""" |
|
|
13 |
Uses the weingarten map to estimate image mean or gaussian curvature |
|
|
14 |
|
|
|
15 |
ANTsR function: `weingartenImageCurvature` |
|
|
16 |
|
|
|
17 |
Arguments |
|
|
18 |
--------- |
|
|
19 |
image : ANTsImage |
|
|
20 |
image from which curvature is calculated |
|
|
21 |
|
|
|
22 |
sigma : scalar |
|
|
23 |
smoothing parameter |
|
|
24 |
|
|
|
25 |
opt : string |
|
|
26 |
mean by default, otherwise `gaussian` or `characterize` |
|
|
27 |
|
|
|
28 |
Returns |
|
|
29 |
------- |
|
|
30 |
ANTsImage |
|
|
31 |
|
|
|
32 |
Example |
|
|
33 |
------- |
|
|
34 |
>>> import ants |
|
|
35 |
>>> image = ants.image_read(ants.get_ants_data('mni')).resample_image((3,3,3)) |
|
|
36 |
>>> imagecurv = ants.weingarten_image_curvature(image) |
|
|
37 |
""" |
|
|
38 |
if image.dimension not in {2,3}: |
|
|
39 |
raise ValueError('image must be 2D or 3D') |
|
|
40 |
|
|
|
41 |
if image.dimension == 2: |
|
|
42 |
d = image.shape |
|
|
43 |
temp = np.zeros(list(d)+[10]) |
|
|
44 |
for k in range(1,7): |
|
|
45 |
voxvals = image[:d[0],:d[1]].numpy() |
|
|
46 |
temp[:d[0],:d[1],k] = voxvals |
|
|
47 |
temp = ants.from_numpy(temp) |
|
|
48 |
myspc = image.spacing |
|
|
49 |
myspc = list(myspc) + [min(myspc)] |
|
|
50 |
temp.set_spacing(myspc) |
|
|
51 |
temp = temp.clone('float') |
|
|
52 |
else: |
|
|
53 |
temp = image.clone('float') |
|
|
54 |
|
|
|
55 |
optnum = 0 |
|
|
56 |
if opt == 'gaussian': |
|
|
57 |
optnum = 6 |
|
|
58 |
if opt == 'characterize': |
|
|
59 |
optnum = 5 |
|
|
60 |
|
|
|
61 |
libfn = get_lib_fn('weingartenImageCurvature') |
|
|
62 |
mykout = libfn(temp.pointer, sigma, optnum) |
|
|
63 |
mykout = ants.from_pointer(mykout) |
|
|
64 |
if image.dimension == 3: |
|
|
65 |
return mykout |
|
|
66 |
elif image.dimension == 2: |
|
|
67 |
subarr = ants.from_numpy(mykout.numpy()[:,:,4]) |
|
|
68 |
return ants.copy_image_info(image, subarr) |