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

Switch to side-by-side view

--- a
+++ b/ants/segmentation/otsu.py
@@ -0,0 +1,44 @@
+
+ 
+__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
+
+
+