[5d12a0]: / ants / math / metrics.py

Download this file

44 lines (30 with data), 1.1 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
__all__ = ['image_mutual_information']
from ants.decorators import image_method
from ants.internal import get_lib_fn
@image_method
def image_mutual_information(image1, image2):
"""
Compute mutual information between two ANTsImage types
ANTsR function: `antsImageMutualInformation`
Arguments
---------
image1 : ANTsImage
image 1
image2 : ANTsImage
image 2
Returns
-------
scalar
Example
-------
>>> import ants
>>> fi = ants.image_read( ants.get_ants_data('r16') ).clone('float')
>>> mi = ants.image_read( ants.get_ants_data('r64') ).clone('float')
>>> mival = ants.image_mutual_information(fi, mi) # -0.1796141
"""
if (image1.pixeltype != 'float') or (image2.pixeltype != 'float'):
raise ValueError('Both images must have float pixeltype')
if image1.dimension != image2.dimension:
raise ValueError('Both images must have same dimension')
libfn = get_lib_fn('antsImageMutualInformation%iD' % image1.dimension)
return libfn(image1.pointer, image2.pointer)