From 23cf8b7dfbec8814168aa3bb2940d1c25d8e0217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Wed, 27 Mar 2013 22:25:59 +0100 Subject: [PATCH 1/2] Make sure non-zero values are treated as True --- skimage/filter/rank/bilateral_rank.pyx | 2 +- skimage/filter/rank/percentile_rank.pyx | 2 +- skimage/filter/rank/rank.pyx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/skimage/filter/rank/bilateral_rank.pyx b/skimage/filter/rank/bilateral_rank.pyx index 04f6cb35..e2a1fcf3 100644 --- a/skimage/filter/rank/bilateral_rank.pyx +++ b/skimage/filter/rank/bilateral_rank.pyx @@ -36,7 +36,7 @@ __all__ = ['bilateral_mean', 'bilateral_pop'] def _apply(func8, func16, image, selem, out, mask, shift_x, shift_y, s0, s1): - selem = img_as_ubyte(selem) + selem = img_as_ubyte(selem > 0) image = np.ascontiguousarray(image) if mask is None: diff --git a/skimage/filter/rank/percentile_rank.pyx b/skimage/filter/rank/percentile_rank.pyx index 7deae623..9db81bcc 100644 --- a/skimage/filter/rank/percentile_rank.pyx +++ b/skimage/filter/rank/percentile_rank.pyx @@ -35,7 +35,7 @@ __all__ = ['percentile_autolevel', 'percentile_gradient', def _apply(func8, func16, image, selem, out, mask, shift_x, shift_y, p0, p1): - selem = img_as_ubyte(selem) + selem = img_as_ubyte(selem > 0) image = np.ascontiguousarray(image) if mask is None: diff --git a/skimage/filter/rank/rank.pyx b/skimage/filter/rank/rank.pyx index 5380363a..2ef5484e 100644 --- a/skimage/filter/rank/rank.pyx +++ b/skimage/filter/rank/rank.pyx @@ -28,7 +28,7 @@ __all__ = ['autolevel', 'bottomhat', 'equalize', 'gradient', 'maximum', 'mean', def _apply(func8, func16, image, selem, out, mask, shift_x, shift_y): - selem = img_as_ubyte(selem) + selem = img_as_ubyte(selem > 0) image = np.ascontiguousarray(image) if mask is None: From 8299f471f22123e02633245d4dd7a17b73edc5d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Wed, 27 Mar 2013 22:26:29 +0100 Subject: [PATCH 2/2] Add test case for different dtypes of structuring element --- skimage/filter/rank/tests/test_rank.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/skimage/filter/rank/tests/test_rank.py b/skimage/filter/rank/tests/test_rank.py index 43ff030f..62363675 100644 --- a/skimage/filter/rank/tests/test_rank.py +++ b/skimage/filter/rank/tests/test_rank.py @@ -376,5 +376,25 @@ def test_entropy(): assert(np.max(rank.entropy(data, selem)) == 12000) +def test_selem_dtypes(): + + image = np.zeros((5, 5), dtype=np.uint8) + out = np.zeros_like(image) + mask = np.ones_like(image, dtype=np.uint8) + image[2, 2] = 255 + image[2, 3] = 128 + image[1, 2] = 16 + + for dtype in (np.uint8, np.uint16, np.int32, np.int64, + np.float32, np.float64): + elem = np.array([[0, 0, 0], [0, 1, 0], [0, 0, 0]], dtype=dtype) + rank.mean(image=image, selem=elem, out=out, mask=mask, + shift_x=0, shift_y=0) + assert_array_equal(image, out) + rank.percentile_mean(image=image, selem=elem, out=out, mask=mask, + shift_x=0, shift_y=0) + assert_array_equal(image, out) + + if __name__ == "__main__": run_module_suite()