Merge pull request #1907 from OrkoHunter/threshold_adaptive_block_size

Modify threshold_adaptive
This commit is contained in:
Juan Nunez-Iglesias committed 2016-01-26 10:26:56 +11:00
commit aae7f2b615
3 files changed
+10 -2

No files matched your search

@@ -26,7 +26,7 @@ image = data.page()
global_thresh = threshold_otsu(image)
binary_global = image > global_thresh
block_size = 40
block_size = 35
binary_adaptive = threshold_adaptive(image, block_size, offset=10)
fig, axes = plt.subplots(nrows=3, figsize=(7, 8))
@@ -203,6 +203,11 @@ def test_yen_coins_image_as_float():
assert 0.43 < threshold_yen(coins) < 0.44
def test_adaptive_even_block_size_error():
img = data.camera()
assert_raises(ValueError, threshold_adaptive, img, block_size=4)
def test_isodata_camera_image():
camera = skimage.img_as_ubyte(data.camera())
+4 -1
View File
@@ -25,7 +25,7 @@ def threshold_adaptive(image, block_size, method='gaussian', offset=0,
image : (N, M) ndarray
Input image.
block_size : int
Uneven size of pixel neighborhood which is used to calculate the
Odd size of pixel neighborhood which is used to calculate the
threshold value (e.g. 3, 5, 7, ..., 21, ...).
method : {'generic', 'gaussian', 'mean', 'median'}, optional
Method used to determine adaptive threshold for local neighbourhood in
@@ -68,6 +68,9 @@ def threshold_adaptive(image, block_size, method='gaussian', offset=0,
>>> func = lambda arr: arr.mean()
>>> binary_image2 = threshold_adaptive(image, 15, 'generic', param=func)
"""
if block_size % 2 == 0:
raise ValueError("The kwarg ``block_size`` must be odd! Given "
"``block_size`` {0} is even.".format(block_size))
assert_nD(image, 2)
thresh_image = np.zeros(image.shape, 'double')
if method == 'generic':