[5d12a0]: / ants / segmentation / otsu.py

Download this file

45 lines (30 with data), 946 Bytes

 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__ = ['otsu_segmentation']
def otsu_segmentation(image, k, mask=None):
"""
Otsu image segmentation
This is a very fast segmentation algorithm good for quick explortation,
but does not return probability maps.
ANTsR function: `thresholdImage(image, 'Otsu', k)`
Arguments
---------
image : ANTsImage
input image
k : integer
integer number of classes. Note that a background class will
be added to this, so the resulting segmentation will
have k+1 unique values.
mask : ANTsImage
segment inside this mask
Returns
-------
ANTsImage
Example
-------
>>> import ants
>>> mni = ants.image_read(ants.get_data('mni'))
>>> seg = mni.otsu_segmentation(k=3) #0=bg,1=csf,2=gm,3=wm
"""
if mask is not None:
image = image.mask_image(mask)
seg = image.threshold_image('Otsu', k)
return seg