Pull request: morphology fix

Tony Yu tsyu80 at gmail.com
Sat Oct 15 04:58:40 EDT 2011


I just submitted a pull request for a somewhat-subtle bug with some
morphology operations:

https://github.com/scikits-image/scikits.image/pull/62

Overly detailed explanation:

Using a structuring element with one-or-both sides being even-numbered gives
buggy output for morphological open/close and white/black tophat operations.
These issues arise because even-numbered structuring elements (selems)
aren't centered on a pixel. The dilate and erode operations are (correctly)
defined so that they are symmetric (dilation on a white feature is exactly
the opposite of erosion on an equivalent black feature). When chaining them
(e.g. open() = dilate(erode())), however, this symmetry ends up shifting
features. To fix this, one of the operations should be shifted. For example,
if erosion is done with the selem shifted slightly to the lower-right, the
dilation operation should shift the selem to the upper-left. This change
prevents features from being shifted.

The open/close operations aren't that bad: they just shift features. But,
when calling white/black tophat operations, the shifting can lead to
over/underflow of pixels. I've attached examples of the lena image after
calling white tophat, both before and after the fix. The underflow should be
apparent in the first image.

Best,
-Tony


Example code:

import os
import numpy as np
import matplotlib.pyplot as plt

from scikits.image import data_dir
from scikits.image.morphology import *

lena = np.load(os.path.join(data_dir, 'lena_GRAY_U8.npy'))

plt.imshow(greyscale_white_top_hat(lena, square(4)))
plt.show()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20111015/6c89f86d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: white_tophat.png
Type: image/png
Size: 244334 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20111015/6c89f86d/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: white_tophat_fixed.png
Type: image/png
Size: 134549 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20111015/6c89f86d/attachment-0001.png>


More information about the scikit-image mailing list