|
a |
|
b/ants/ops/threshold_image.py |
|
|
1 |
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
__all__ = ['threshold_image'] |
|
|
5 |
|
|
|
6 |
from ants.decorators import image_method |
|
|
7 |
from ants.internal import get_lib_fn, process_arguments |
|
|
8 |
|
|
|
9 |
@image_method |
|
|
10 |
def threshold_image(image, low_thresh=None, high_thresh=None, inval=1, outval=0, binary=True): |
|
|
11 |
""" |
|
|
12 |
Converts a scalar image into a binary image by thresholding operations |
|
|
13 |
|
|
|
14 |
ANTsR function: `thresholdImage` |
|
|
15 |
|
|
|
16 |
Arguments |
|
|
17 |
--------- |
|
|
18 |
image : ANTsImage |
|
|
19 |
Input image to operate on |
|
|
20 |
|
|
|
21 |
low_thresh : scalar (optional) |
|
|
22 |
Lower edge of threshold window |
|
|
23 |
|
|
|
24 |
hight_thresh : scalar (optional) |
|
|
25 |
Higher edge of threshold window |
|
|
26 |
|
|
|
27 |
inval : scalar |
|
|
28 |
Output value for image voxels in between lothresh and hithresh |
|
|
29 |
|
|
|
30 |
outval : scalar |
|
|
31 |
Output value for image voxels lower than lothresh or higher than hithresh |
|
|
32 |
|
|
|
33 |
binary : boolean |
|
|
34 |
if true, returns binary thresholded image |
|
|
35 |
if false, return binary thresholded image multiplied by original image |
|
|
36 |
|
|
|
37 |
Returns |
|
|
38 |
------- |
|
|
39 |
ANTsImage |
|
|
40 |
|
|
|
41 |
Example |
|
|
42 |
------- |
|
|
43 |
>>> import ants |
|
|
44 |
>>> image = ants.image_read( ants.get_ants_data('r16') ) |
|
|
45 |
>>> timage = ants.threshold_image(image, 0.5, 1e15) |
|
|
46 |
""" |
|
|
47 |
if high_thresh is None: |
|
|
48 |
high_thresh = image.max() + 0.01 |
|
|
49 |
if low_thresh is None: |
|
|
50 |
low_thresh = image.min() - 0.01 |
|
|
51 |
dim = image.dimension |
|
|
52 |
outimage = image.clone() |
|
|
53 |
args = [dim, image, outimage, low_thresh, high_thresh, inval, outval] |
|
|
54 |
processed_args = process_arguments(args) |
|
|
55 |
libfn = get_lib_fn('ThresholdImage') |
|
|
56 |
libfn(processed_args) |
|
|
57 |
if binary: |
|
|
58 |
return outimage |
|
|
59 |
else: |
|
|
60 |
return outimage*image |
|
|
61 |
|