From b1d99be7352bbaa4e036858e32c27943a6998dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Tue, 11 Sep 2012 07:41:53 +0200 Subject: [PATCH] Fix bug in grey erosion and dilation --- skimage/morphology/cmorph.pyx | 6 +++--- skimage/morphology/tests/test_grey.py | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/skimage/morphology/cmorph.pyx b/skimage/morphology/cmorph.pyx index fb1e3af1..9b8b3a27 100644 --- a/skimage/morphology/cmorph.pyx +++ b/skimage/morphology/cmorph.pyx @@ -51,7 +51,7 @@ def dilate(np.ndarray[np.uint8_t, ndim=2] image, rr = r + sr[s] cc = c + sc[s] if 0 <= rr < rows and 0 <= cc < cols: - value = image_data[rr * rows + cc] + value = image_data[rr * cols + cc] if value > local_max: local_max = value @@ -85,7 +85,7 @@ def erode(np.ndarray[np.uint8_t, ndim=2] image, cdef np.uint8_t* out_data = out.data cdef np.uint8_t* image_data = image.data - cdef int r, c, rr, cc, s, value, local_max + cdef int r, c, rr, cc, s, value, local_min cdef int selem_num = np.sum(selem != 0) cdef int* sr = malloc(selem_num * sizeof(int)) @@ -106,7 +106,7 @@ def erode(np.ndarray[np.uint8_t, ndim=2] image, rr = r + sr[s] cc = c + sc[s] if 0 <= rr < rows and 0 <= cc < cols: - value = image_data[rr * rows + cc] + value = image_data[rr * cols + cc] if value < local_min: local_min = value diff --git a/skimage/morphology/tests/test_grey.py b/skimage/morphology/tests/test_grey.py index 6003425f..6d2b75e8 100644 --- a/skimage/morphology/tests/test_grey.py +++ b/skimage/morphology/tests/test_grey.py @@ -5,6 +5,7 @@ from numpy import testing import skimage from skimage import data_dir +from skimage.util import img_as_bool from skimage.morphology import binary, grey, selem @@ -157,28 +158,28 @@ class TestDTypes(): def test_binary_erosion(): strel = selem.square(3) binary_res = binary.binary_erosion(bw_lena, strel) - grey_res = grey.erosion(bw_lena, strel) + grey_res = img_as_bool(grey.erosion(bw_lena, strel)) testing.assert_array_equal(binary_res, grey_res) def test_binary_dilation(): strel = selem.square(3) binary_res = binary.binary_dilation(bw_lena, strel) - grey_res = grey.dilation(bw_lena, strel) + grey_res = img_as_bool(grey.dilation(bw_lena, strel)) testing.assert_array_equal(binary_res, grey_res) def test_binary_closing(): strel = selem.square(3) binary_res = binary.binary_closing(bw_lena, strel) - grey_res = grey.closing(bw_lena, strel) + grey_res = img_as_bool(grey.closing(bw_lena, strel)) testing.assert_array_equal(binary_res, grey_res) def test_binary_opening(): strel = selem.square(3) binary_res = binary.binary_opening(bw_lena, strel) - grey_res = grey.opening(bw_lena, strel) + grey_res = img_as_bool(grey.opening(bw_lena, strel)) testing.assert_array_equal(binary_res, grey_res)