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

Download this file

41 lines (31 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
__all__ = ["hausdorff_distance"]
from ants.decorators import image_method
from ants.internal import get_lib_fn
@image_method
def hausdorff_distance(image1, image2):
"""
Get Hausdorff distance between non-zero pixels in two images
ANTsR function: `hausdorffDistance`
Arguments
---------
source image : ANTsImage
Source image
target_image : ANTsImage
Target image
Returns
-------
data frame with "Distance" and "AverageDistance"
Example
-------
>>> import ants
>>> r16 = ants.image_read( ants.get_ants_data('r16') )
>>> r64 = ants.image_read( ants.get_ants_data('r64') )
>>> s16 = ants.kmeans_segmentation( r16, 3 )['segmentation']
>>> s64 = ants.kmeans_segmentation( r64, 3 )['segmentation']
>>> stats = ants.hausdorff_distance(s16, s64)
"""
image1_int = image1.clone("unsigned int")
image2_int = image2.clone("unsigned int")
libfn = get_lib_fn("hausdorffDistance%iD" % image1_int.dimension)
d = libfn(image1_int.pointer, image2_int.pointer)
return d