From 1ef98dae8c1cabbdc7324109b9a312ac23e7bc40 Mon Sep 17 00:00:00 2001 From: Chintak Sheth Date: Thu, 23 May 2013 23:24:17 +0530 Subject: [PATCH] Ability to choose the type of connectivity and ValueError --- skimage/morphology/convex_hull.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/skimage/morphology/convex_hull.py b/skimage/morphology/convex_hull.py index 5b8f2c4c..b6e1b43a 100644 --- a/skimage/morphology/convex_hull.py +++ b/skimage/morphology/convex_hull.py @@ -66,7 +66,7 @@ def convex_hull_image(image): return mask -def convex_hull_object(image): +def convex_hull_object(image, neighbors=8): """Compute the convex hull image of individual objects in a binary image. The convex hull is the set of pixels included in the smallest convex @@ -76,6 +76,8 @@ def convex_hull_object(image): ---------- image : ndarray Binary input image. + neighbors : {4, 8}, int + Whether to use 4- or 8-connectivity. Returns ------- @@ -94,7 +96,10 @@ def convex_hull_object(image): """ - labeled_im = label(image, neighbors=8, background=0) + if neighbors != 4 and neighbors != 8: + raise ValueError('Neighbors must be either 4 or 8.') + + labeled_im = label(image, neighbors, background=0) convex_obj = np.zeros(image.shape, dtype=bool) convex_img = np.zeros(image.shape, dtype=bool)