From 3b4425813b03b692a8ef95a3f205f1a6af6c4091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20T=C3=BD=C4=8D?= Date: Tue, 25 Nov 2014 00:37:19 +0100 Subject: [PATCH] Streamlined connectivity vs neighbors handling --- skimage/measure/_ccomp.pyx | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/skimage/measure/_ccomp.pyx b/skimage/measure/_ccomp.pyx index 00c0645e..e9ee2514 100644 --- a/skimage/measure/_ccomp.pyx +++ b/skimage/measure/_ccomp.pyx @@ -409,20 +409,19 @@ def label(input, neighbors=None, background=None, return_num=False, get_bginfo(background, &bg) if neighbors is None and connectivity is None: - # default - connectivity = -1 + # use the full connectivity by default + connectivity = input.ndim elif neighbors is not None: - depr_msg = ("The argument 'neighbors' is deprecated, use " - "'connectivity' instead") - DeprecationWarning(depr_msg) - # fail - if neighbors != 4 and neighbors != 8: - msg = "Neighbors must be either 4 or 8, got '%d'.\n" % neighbors - raise ValueError(msg) + DeprecationWarning("The argument 'neighbors' is deprecated, use " + "'connectivity' instead") + # backwards-compatible neighbors recalc to connectivity, + if neighbors == 4: + connectivity = 1 + elif neighbors == 8: + connectivity = input.ndim else: - # backwards-compatible neighbors recalc to connectivity, - nei2conn = {4: 1, 8: -1} - connectivity = nei2conn[neighbors] + raise ValueError("Neighbors must be either 4 or 8, got '%d'.\n" + % neighbors) connectivity = _norm_connectivity(connectivity, shapeinfo.ndim)