From d0d71427af3c7d0256d13f0d5f0baa967a2ca357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Scho=CC=88nberger?= Date: Tue, 24 Apr 2012 20:53:26 +0200 Subject: [PATCH] added mean method to adaptive thresholding --- skimage/filter/_thresholding.pyx | 3 +++ skimage/filter/thresholding.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/skimage/filter/_thresholding.pyx b/skimage/filter/_thresholding.pyx index 303c1a5f..88badf31 100644 --- a/skimage/filter/_thresholding.pyx +++ b/skimage/filter/_thresholding.pyx @@ -19,6 +19,9 @@ def _adaptive_threshold( sigma = (block_size - 1) / 6.0 mean_image = scipy.ndimage.gaussian_filter(image, sigma) elif method == 'mean': + mask = 1. / block_size**2 * np.ones((block_size, block_size)) + mean_image = scipy.ndimage.convolve(image, mask) + elif method == 'median': mean_image = scipy.ndimage.median_filter(image, block_size) for r in range(image.shape[0]): diff --git a/skimage/filter/thresholding.py b/skimage/filter/thresholding.py index d0d95a4a..09e6eaea 100644 --- a/skimage/filter/thresholding.py +++ b/skimage/filter/thresholding.py @@ -25,8 +25,8 @@ def adaptive_threshold(image, block_size, offset, method='gaussian'): constant subtracted from weighted mean of neighborhood to calculate the local threshold value method : string, optional - thresholding type which must be one of `gaussian` or `mean`. - By default the `gaussian` method is used. + thresholding type which must be one of 'gaussian', 'mean' or 'median'. + By default the 'gaussian' method is used. Returns -------