From ac2714d3c8e690e1de4e89cee1b8bac3191acfc8 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Sat, 15 Oct 2011 03:34:30 -0400 Subject: [PATCH] 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. --- scikits/image/morphology/grey.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scikits/image/morphology/grey.py b/scikits/image/morphology/grey.py index 0b8c49b8..463e55b2 100644 --- a/scikits/image/morphology/grey.py +++ b/scikits/image/morphology/grey.py @@ -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):