attempt to fix #1567

add asseert_ND=2 to all threshold functions

Simpler writing, less cases

Fix variable name
This commit is contained in:
François Boulogne
2015-06-24 16:53:28 -04:00
parent 7132df764e
commit 6f1e84de95
+8 -8
View File
@@ -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