|
a |
|
b/ants/label/label_stats.py |
|
|
1 |
__all__ = ["label_stats"] |
|
|
2 |
|
|
|
3 |
import pandas as pd |
|
|
4 |
|
|
|
5 |
from ants.internal import get_lib_fn |
|
|
6 |
from ants.decorators import image_method |
|
|
7 |
|
|
|
8 |
@image_method |
|
|
9 |
def label_stats(image, label_image): |
|
|
10 |
""" |
|
|
11 |
Get label statistics from image |
|
|
12 |
|
|
|
13 |
ANTsR function: `labelStats` |
|
|
14 |
|
|
|
15 |
Arguments |
|
|
16 |
--------- |
|
|
17 |
image : ANTsImage |
|
|
18 |
Image from which statistics will be calculated |
|
|
19 |
|
|
|
20 |
label_image : ANTsImage |
|
|
21 |
Label image |
|
|
22 |
|
|
|
23 |
Returns |
|
|
24 |
------- |
|
|
25 |
ndarray ? |
|
|
26 |
|
|
|
27 |
Example |
|
|
28 |
------- |
|
|
29 |
>>> import ants |
|
|
30 |
>>> image = ants.image_read( ants.get_ants_data('r16') , 2 ) |
|
|
31 |
>>> image = ants.resample_image( image, (64,64), 1, 0 ) |
|
|
32 |
>>> mask = ants.get_mask(image) |
|
|
33 |
>>> segs1 = ants.kmeans_segmentation( image, 3 ) |
|
|
34 |
>>> stats = ants.label_stats(image, segs1['segmentation']) |
|
|
35 |
""" |
|
|
36 |
image_float = image.clone("float") |
|
|
37 |
label_image_int = label_image.clone("unsigned int") |
|
|
38 |
|
|
|
39 |
libfn = get_lib_fn("labelStats%iD" % image.dimension) |
|
|
40 |
df = libfn(image_float.pointer, label_image_int.pointer) |
|
|
41 |
df = pd.DataFrame(df) |
|
|
42 |
df.sort_values(by=["LabelValue"], inplace=True) |
|
|
43 |
return df |