|
a |
|
b/ants/math/hausdorff_distance.py |
|
|
1 |
__all__ = ["hausdorff_distance"] |
|
|
2 |
|
|
|
3 |
from ants.decorators import image_method |
|
|
4 |
from ants.internal import get_lib_fn |
|
|
5 |
|
|
|
6 |
@image_method |
|
|
7 |
def hausdorff_distance(image1, image2): |
|
|
8 |
""" |
|
|
9 |
Get Hausdorff distance between non-zero pixels in two images |
|
|
10 |
|
|
|
11 |
ANTsR function: `hausdorffDistance` |
|
|
12 |
|
|
|
13 |
Arguments |
|
|
14 |
--------- |
|
|
15 |
source image : ANTsImage |
|
|
16 |
Source image |
|
|
17 |
|
|
|
18 |
target_image : ANTsImage |
|
|
19 |
Target image |
|
|
20 |
|
|
|
21 |
Returns |
|
|
22 |
------- |
|
|
23 |
data frame with "Distance" and "AverageDistance" |
|
|
24 |
|
|
|
25 |
Example |
|
|
26 |
------- |
|
|
27 |
>>> import ants |
|
|
28 |
>>> r16 = ants.image_read( ants.get_ants_data('r16') ) |
|
|
29 |
>>> r64 = ants.image_read( ants.get_ants_data('r64') ) |
|
|
30 |
>>> s16 = ants.kmeans_segmentation( r16, 3 )['segmentation'] |
|
|
31 |
>>> s64 = ants.kmeans_segmentation( r64, 3 )['segmentation'] |
|
|
32 |
>>> stats = ants.hausdorff_distance(s16, s64) |
|
|
33 |
""" |
|
|
34 |
image1_int = image1.clone("unsigned int") |
|
|
35 |
image2_int = image2.clone("unsigned int") |
|
|
36 |
|
|
|
37 |
libfn = get_lib_fn("hausdorffDistance%iD" % image1_int.dimension) |
|
|
38 |
d = libfn(image1_int.pointer, image2_int.pointer) |
|
|
39 |
|
|
|
40 |
return d |