|
a |
|
b/ants/math/metrics.py |
|
|
1 |
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
__all__ = ['image_mutual_information'] |
|
|
5 |
|
|
|
6 |
|
|
|
7 |
from ants.decorators import image_method |
|
|
8 |
from ants.internal import get_lib_fn |
|
|
9 |
|
|
|
10 |
@image_method |
|
|
11 |
def image_mutual_information(image1, image2): |
|
|
12 |
""" |
|
|
13 |
Compute mutual information between two ANTsImage types |
|
|
14 |
|
|
|
15 |
ANTsR function: `antsImageMutualInformation` |
|
|
16 |
|
|
|
17 |
Arguments |
|
|
18 |
--------- |
|
|
19 |
image1 : ANTsImage |
|
|
20 |
image 1 |
|
|
21 |
|
|
|
22 |
image2 : ANTsImage |
|
|
23 |
image 2 |
|
|
24 |
|
|
|
25 |
Returns |
|
|
26 |
------- |
|
|
27 |
scalar |
|
|
28 |
|
|
|
29 |
Example |
|
|
30 |
------- |
|
|
31 |
>>> import ants |
|
|
32 |
>>> fi = ants.image_read( ants.get_ants_data('r16') ).clone('float') |
|
|
33 |
>>> mi = ants.image_read( ants.get_ants_data('r64') ).clone('float') |
|
|
34 |
>>> mival = ants.image_mutual_information(fi, mi) # -0.1796141 |
|
|
35 |
""" |
|
|
36 |
if (image1.pixeltype != 'float') or (image2.pixeltype != 'float'): |
|
|
37 |
raise ValueError('Both images must have float pixeltype') |
|
|
38 |
|
|
|
39 |
if image1.dimension != image2.dimension: |
|
|
40 |
raise ValueError('Both images must have same dimension') |
|
|
41 |
|
|
|
42 |
libfn = get_lib_fn('antsImageMutualInformation%iD' % image1.dimension) |
|
|
43 |
return libfn(image1.pointer, image2.pointer) |