Fix morphological open/close for square structuring elements with even sides.

This also fixes rectangular selems with even sides, but not rectangular selems with one odd and one even side.
This commit is contained in:
Tony S Yu
2011-10-15 03:34:30 -04:00
parent fb92bfcf71
commit ac2714d3c8
+12 -2
View File
@@ -105,8 +105,13 @@ def greyscale_open(image, selem, out=None):
opening : ndarray
The result of the morphological opening.
"""
h, w = selem.shape
if (h % 2) == 0 and (w % 2) == 0:
flip = True
else:
flip = False
eroded = greyscale_erode(image, selem)
out = greyscale_dilate(eroded, selem, out=out)
out = greyscale_dilate(eroded, selem, out=out, flip=flip)
return out
def greyscale_close(image, selem, out=None):
@@ -131,8 +136,13 @@ def greyscale_close(image, selem, out=None):
opening : ndarray
The result of the morphological opening.
"""
h, w = selem.shape
if (h % 2) == 0 and (w % 2) == 0:
flip = True
else:
flip = False
dilated = greyscale_dilate(image, selem)
out = greyscale_erode(dilated, selem, out=out)
out = greyscale_erode(dilated, selem, out=out, flip=flip)
return out
def greyscale_white_top_hat(image, selem, out=None):