Modify threshold_adaptive

1. Improve docstring
2. Raise error for even block_size
3. Test for the ValueError
This commit is contained in:
Himanshu Mishra
2016-01-25 19:46:21 +05:30
parent a2379182dc
commit 41afd05d0a
2 changed files with 12 additions and 2 deletions
+8 -1
View File
@@ -1,5 +1,7 @@
import numpy as np
from numpy.testing import assert_equal, assert_almost_equal
from numpy.testing import (assert_equal,
assert_almost_equal,
assert_raises)
import skimage
from skimage import data
@@ -196,6 +198,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':