From 7a4b74f0573d0e5ffb928d29fa75d64efa3cff72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Tue, 5 Jul 2016 15:53:02 +0200 Subject: [PATCH] remove local threshold in try_all_threshold --- .../segmentation/plot_thresholding.py | 3 +- .../xx_applications/plot_thresholding.py | 5 +-- skimage/filters/thresholding.py | 36 ++----------------- 3 files changed, 4 insertions(+), 40 deletions(-) diff --git a/doc/examples/segmentation/plot_thresholding.py b/doc/examples/segmentation/plot_thresholding.py index 9a3ccb0d..6adb9cf5 100644 --- a/doc/examples/segmentation/plot_thresholding.py +++ b/doc/examples/segmentation/plot_thresholding.py @@ -68,6 +68,5 @@ img = data.page() # Here, we specify a radius for local thresholding algorithms. # If it is not specified, only global algorithms are called. -fig, ax = try_all_threshold(img, radius=20, - figsize=(10, 8), verbose=False) +fig, ax = try_all_threshold(img, figsize=(10, 8), verbose=False) plt.show() diff --git a/doc/examples/xx_applications/plot_thresholding.py b/doc/examples/xx_applications/plot_thresholding.py index 92e4556b..7a30807f 100644 --- a/doc/examples/xx_applications/plot_thresholding.py +++ b/doc/examples/xx_applications/plot_thresholding.py @@ -36,10 +36,7 @@ from skimage.filters import try_all_threshold img = data.page() -# Here, we specify a radius for local thresholding algorithms. -# If it is not specified, only global algorithms are called. -fig, ax = try_all_threshold(img, radius=20, - figsize=(10, 8), verbose=False) +fig, ax = try_all_threshold(img, figsize=(10, 8), verbose=False) plt.show() ###################################################################### diff --git a/skimage/filters/thresholding.py b/skimage/filters/thresholding.py index 06493880..36435e33 100644 --- a/skimage/filters/thresholding.py +++ b/skimage/filters/thresholding.py @@ -5,8 +5,6 @@ from scipy.ndimage import filters as ndif from collections import OrderedDict from ..exposure import histogram from .._shared.utils import assert_nD, warn -from ..morphology import disk -from ..filters.rank import otsu __all__ = ['try_all_threshold', 'threshold_adaptive', @@ -68,16 +66,13 @@ def _try_all(image, methods=None, figsize=None, num_cols=2, verbose=True): return fig, ax -def try_all_threshold(image, radius=None, figsize=(8, 5), verbose=True): +def try_all_threshold(image, figsize=(8, 5), verbose=True): """Returns a figure comparing the outputs of different thresholding methods. Parameters ---------- image : (N, M) ndarray Input image. - radius : int, optional - Lengthscale used for local methods. - If None, local methods are ignored. figsize : tuple, optional Figure size (in inches). verbose : bool, optional @@ -99,28 +94,12 @@ def try_all_threshold(image, radius=None, figsize=(8, 5), verbose=True): * otsu * triangle * yen - * adaptive threshold (local) - * rank otsu (local) Examples -------- >>> from skimage.data import text - >>> fig, ax = try_all_threshold(text(), radius=20, - ... figsize=(10, 6), verbose=False) + >>> fig, ax = try_all_threshold(text(), figsize=(10, 6), verbose=False) """ - - def include_selem(func, *args, **kwargs): - """ - A wrapper function to embed a threshold range for local algorithms. - """ - def wrapper(im): - return func(im, *args, **kwargs) - try: - wrapper.__orifunc__ = func.__orifunc__ - except AttributeError: - wrapper.__orifunc__ = func.__module__ + '.' + func.__name__ - return wrapper - def thresh(func): """ A wrapper function to return a thresholded image. @@ -142,17 +121,6 @@ def try_all_threshold(image, radius=None, figsize=(8, 5), verbose=True): 'Triangle': thresh(threshold_triangle), 'Yen': thresh(threshold_yen)}) - # Local algorithms. - if radius is not None: - selem = disk(radius) - local_otsu = include_selem(otsu, selem) - methods['Local Otsu'] = thresh(local_otsu) - - block_size = 2 * int(radius) + 1 - adaptive_threshold = include_selem(threshold_adaptive, block_size, - offset=10) - methods['Adaptive threshold'] = adaptive_threshold - return _try_all(image, figsize=figsize, methods=methods, verbose=verbose)