Diff of /ants/segmentation/otsu.py [000000] .. [5d12a0]

Switch to unified view

a b/ants/segmentation/otsu.py
1
2
 
3
__all__ = ['otsu_segmentation']
4
5
def otsu_segmentation(image, k, mask=None):
6
    """
7
    Otsu image segmentation
8
9
    This is a very fast segmentation algorithm good for quick explortation, 
10
    but does not return probability maps.
11
12
    ANTsR function: `thresholdImage(image, 'Otsu', k)`
13
    
14
    Arguments
15
    ---------
16
    image : ANTsImage 
17
        input image
18
    
19
    k : integer
20
        integer number of classes. Note that a background class will 
21
        be added to this, so the resulting segmentation will 
22
        have k+1 unique values.
23
    
24
    mask : ANTsImage 
25
        segment inside this mask
26
27
    Returns
28
    -------
29
    ANTsImage
30
31
    Example
32
    -------
33
    >>> import ants
34
    >>> mni = ants.image_read(ants.get_data('mni'))
35
    >>> seg = mni.otsu_segmentation(k=3) #0=bg,1=csf,2=gm,3=wm
36
    """
37
    if mask is not None:
38
        image = image.mask_image(mask)
39
40
    seg = image.threshold_image('Otsu', k)
41
    return seg
42
43
44