diff --git a/skimage/morphology/binary.py b/skimage/morphology/binary.py index d5e0d92b..5b019051 100644 --- a/skimage/morphology/binary.py +++ b/skimage/morphology/binary.py @@ -31,11 +31,11 @@ def binary_erosion(image, selem=None, out=None): The result of the morphological erosion with values in ``[0, 1]``. """ - + # Default structure element if selem is None: selem = _default_selem(image.ndim) - + selem = (selem != 0) selem_sum = np.sum(selem) @@ -80,11 +80,11 @@ def binary_dilation(image, selem=None, out=None): The result of the morphological dilation with values in ``[0, 1]``. """ - + # Default structure element if selem is None: selem = _default_selem(image.ndim) - + selem = (selem != 0) if np.sum(selem) <= 255: diff --git a/skimage/morphology/grey.py b/skimage/morphology/grey.py index e50e1460..2b4a01a8 100644 --- a/skimage/morphology/grey.py +++ b/skimage/morphology/grey.py @@ -59,7 +59,7 @@ def erosion(image, selem=None, out=None, shift_x=False, shift_y=False): # Default structure element if selem is None: selem = _default_selem(image.ndim) - + if image is out: raise NotImplementedError("In-place erosion not supported!") image = img_as_ubyte(image) @@ -117,7 +117,7 @@ def dilation(image, selem=None, out=None, shift_x=False, shift_y=False): # Default structure element if selem is None: selem = _default_selem(image.ndim) - + if image is out: raise NotImplementedError("In-place dilation not supported!") image = img_as_ubyte(image) @@ -168,11 +168,11 @@ def opening(image, selem=None, out=None): [0, 0, 0, 0, 0]], dtype=uint8) """ - + # Default structure element if selem is None: selem = _default_selem(image.ndim) - + h, w = selem.shape shift_x = True if (w % 2) == 0 else False shift_y = True if (h % 2) == 0 else False @@ -228,7 +228,7 @@ def closing(image, selem=None, out=None): # Default structure element if selem is None: selem = _default_selem(image.ndim) - + h, w = selem.shape shift_x = True if (w % 2) == 0 else False shift_y = True if (h % 2) == 0 else False @@ -279,11 +279,11 @@ def white_tophat(image, selem=None, out=None): [0, 0, 0, 0, 0]], dtype=uint8) """ - + # Default structure element if selem is None: selem = _default_selem(image.ndim) - + if image is out: raise NotImplementedError("Cannot perform white top hat in place.") @@ -338,7 +338,7 @@ def black_tophat(image, selem=None, out=None): # Default structure element if selem is None: selem = _default_selem(image.ndim) - + if image is out: raise NotImplementedError("Cannot perform white top hat in place.") diff --git a/skimage/morphology/selem.py b/skimage/morphology/selem.py index 24adfce6..4147d93b 100644 --- a/skimage/morphology/selem.py +++ b/skimage/morphology/selem.py @@ -292,7 +292,7 @@ def star(a, dtype=np.uint8): selem[selem > 0] = 1 return selem.astype(dtype) - + def _default_selem(ndim): """ Generates a cross-shaped structuring element (connectivity=1). This is the diff --git a/skimage/morphology/tests/test_binary.py b/skimage/morphology/tests/test_binary.py index e6d80321..6ac5e8d8 100644 --- a/skimage/morphology/tests/test_binary.py +++ b/skimage/morphology/tests/test_binary.py @@ -65,10 +65,8 @@ def test_out_argument(): testing.assert_array_equal(out, func(img, strel)) def test_default_selem(): - functions = [binary.binary_erosion, binary.binary_dilation, binary.binary_opening, binary.binary_closing] - strel = selem.diamond(radius=1) image = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], @@ -83,11 +81,10 @@ def test_default_selem(): [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], np.uint8) - for function in functions: im_expected = function(image, strel) im_test = function(image) yield testing.assert_array_equal, im_expected, im_test - + if __name__ == '__main__': testing.run_module_suite() diff --git a/skimage/morphology/tests/test_grey.py b/skimage/morphology/tests/test_grey.py index d298b1eb..359a2832 100644 --- a/skimage/morphology/tests/test_grey.py +++ b/skimage/morphology/tests/test_grey.py @@ -120,11 +120,9 @@ class TestEccentricStructuringElements(): assert np.all(tophat == 0) def test_default_selem(): - functions = [grey.erosion, grey.dilation, grey.opening, grey.closing, grey.white_tophat, grey.black_tophat] - strel = selem.diamond(radius=1) image = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], @@ -139,13 +137,11 @@ def test_default_selem(): [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], np.uint8) - for function in functions: im_expected = function(image, strel) im_test = function(image) yield testing.assert_array_equal, im_expected, im_test - - + class TestDTypes(): def setUp(self):