From 8c9d8926c881e55a2bcb0fcbc9cb52b066aa8e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Thu, 2 Jun 2016 10:31:40 +0200 Subject: [PATCH] Minor enhancements --- doc/examples/filters/plot_threshold_minimum.py | 2 +- skimage/filters/thresholding.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/doc/examples/filters/plot_threshold_minimum.py b/doc/examples/filters/plot_threshold_minimum.py index dbbb7324..950d34d2 100644 --- a/doc/examples/filters/plot_threshold_minimum.py +++ b/doc/examples/filters/plot_threshold_minimum.py @@ -7,7 +7,7 @@ The minimum algorithm takes a histogram of the image and smooths it repeatedly until there are only two peaks in the histogram. Then it finds the minimum value between the two peaks. After smoothing the histogram, there can be multiple pixel values with the minimum histogram -count, so you can pick 'min', 'mid', or 'max' of these values. +count, so you can pick the 'min', 'mid', or 'max' of these values. """ import matplotlib.pyplot as plt diff --git a/skimage/filters/thresholding.py b/skimage/filters/thresholding.py index ffab8748..241a1a85 100644 --- a/skimage/filters/thresholding.py +++ b/skimage/filters/thresholding.py @@ -112,7 +112,7 @@ def threshold_otsu(image, nbins=256): threshold : float Upper threshold value. All pixels intensities that less or equal of this value assumed as foreground. - + Raises ------ ValueError @@ -395,11 +395,11 @@ def threshold_li(image): return threshold + immin -def threshold_minimum(image, nbins=256, bias='min'): +def threshold_minimum(image, nbins=256, bias='min', max_iter=10000): """Return threshold value based on minimum method. - A histogram is computed and smoothed until there are only two maximums. - Then the minimum between these is found. + The histogram of the input `image` is computed and smoothed until there are + only two maxima. Then the minimum in between is the threshold value. Parameters ---------- @@ -411,11 +411,14 @@ def threshold_minimum(image, nbins=256, bias='min'): bias : {'min', 'mid', 'max'}, optional 'min', 'mid', 'max' return lowest, middle, or highest pixel value with minimum histogram value. + max_iter: int, optional + Maximum number of iterations to smooth the histogram. Returns ------- threshold : float - Computed threshold value. + Upper threshold value. All pixels with an intensity higher than + this value are assumed to be foreground. Raises ------ @@ -456,7 +459,6 @@ def threshold_minimum(image, nbins=256, bias='min'): hist, bin_centers = histogram(image.ravel(), nbins) - max_iter = 10000 smooth_hist = np.copy(hist) for counter in range(max_iter): smooth_hist = ndif.uniform_filter1d(smooth_hist, 3) @@ -466,7 +468,7 @@ def threshold_minimum(image, nbins=256, bias='min'): if len(maximums) != 2: raise RuntimeError('Unable to find two maxima in histogram') elif counter == max_iter - 1: - raise RuntimeError('Maximum iteration reached for histogram histogram' + raise RuntimeError('Maximum iteration reached for histogram' 'smoothing') # Find lowest point between the maxima, biased to the low end (min)