From 6f1e84de95a9066bbc1fa6b4a05ec10368f4bb27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Wed, 24 Jun 2015 16:53:28 -0400 Subject: [PATCH] attempt to fix #1567 add asseert_ND=2 to all threshold functions Simpler writing, less cases Fix variable name --- skimage/filters/thresholding.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/skimage/filters/thresholding.py b/skimage/filters/thresholding.py index d962c562..272641ae 100644 --- a/skimage/filters/thresholding.py +++ b/skimage/filters/thresholding.py @@ -245,7 +245,6 @@ def threshold_isodata(image, nbins=256, return_all=False): >>> thresh = threshold_isodata(image) >>> binary = image > thresh """ - hist, bin_centers = histogram(image.ravel(), nbins) # image only contains one unique value @@ -335,15 +334,16 @@ def threshold_li(image): >>> thresh = threshold_li(image) >>> binary = image > thresh """ + # Copy to ensure input image is not modified + image = image.copy() # Requires positive image (because of log(mean)) - offset = image.min() - # Can not use fixed tolerance for float image - imrange = image.max() - offset - image -= offset + immin = np.min(image) + image -= immin + imrange = np.max(image) + tolerance = 0.5 * imrange / 256 - tolerance = 0.5 * imrange / 256.0 # Calculate the mean gray-level - mean = image.mean() + mean = np.mean(image) # Initial estimate new_thresh = mean @@ -365,4 +365,4 @@ def threshold_li(image): else: new_thresh = temp + tolerance - return threshold + offset + return threshold + immin