Merge pull request #310 from ahojnnes/morph

BUG: Fix bug in grey erosion and dilation.
This commit is contained in:
Stefan van der Walt
2012-09-11 11:30:20 -07:00
3 changed files with 17 additions and 9 deletions
+1 -1
View File
@@ -65,7 +65,7 @@ def binary_dilation(image, selem, out=None):
"""
conv = ndimage.convolve(image > 0, selem, output=out,
mode='constant', cval=1)
mode='constant', cval=0)
if conv is not None:
out = conv
return np.not_equal(out, 0, out=out)
+3 -3
View File
@@ -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 = <np.uint8_t*>out.data
cdef np.uint8_t* image_data = <np.uint8_t*>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 = <int*>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
+13 -5
View File
@@ -5,11 +5,12 @@ 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
lena = np.load(os.path.join(data_dir, 'lena_GRAY_U8.npy'))
bw_lena = lena > 0.4
bw_lena = lena > 100
class TestMorphology():
@@ -154,31 +155,38 @@ class TestDTypes():
self._test_image(image)
def test_non_square_image():
strel = selem.square(3)
binary_res = binary.binary_erosion(bw_lena[:100, :200], strel)
grey_res = img_as_bool(grey.erosion(bw_lena[:100, :200], strel))
testing.assert_array_equal(binary_res, grey_res)
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)