proposed fix and test for broken watershed on flat areas (https://github.com/scikit-image/scikit-image/issues/803)

This commit is contained in:
kpk09
2015-05-28 13:28:16 -04:00
committed by Lee Kamentsky
parent fb66edd753
commit a9bdaaf274
2 changed files with 20 additions and 3 deletions
+4 -3
View File
@@ -83,10 +83,11 @@ def watershed(DTYPE_INT32_t[::1] image,
not mask[index]:
continue
new_elem.value = image[index]
new_elem.age = elem.age + 1
new_elem.index = index
age += 1
new_elem.value = image[index]
new_elem.age = age
new_elem.index = index
output[index] = output[old_index]
#
# Push the neighbor onto the heap to work on it later
@@ -385,6 +385,22 @@ class TestWatershed(unittest.TestCase):
scipy.ndimage.watershed_ift(image.astype(np.uint16), markers,
self.eight)
def test_watershed10(self):
"watershed 10"
data = np.array([[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]], np.uint8)
markers = np.array([[1, 0, 0, 2],
[0, 0, 0, 0],
[0, 0, 0, 0],
[3, 0, 0, 4]], np.int8)
out = watershed(data, markers, self.eight)
error = diff([[1, 1, 2, 2],
[1, 1, 2, 2],
[3, 3, 4, 4],
[3, 3, 4, 4]], out)
self.assertTrue(error < eps)
if __name__ == "__main__":
np.testing.run_module_suite()