From d256b6f5b93c5650252409ff9fcf25121c8d7ca3 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Thu, 8 May 2014 18:04:03 +0200 Subject: [PATCH] Move implementation of label to measure submodule --- skimage/measure/__init__.py | 2 +- .../ccomp.pxd => measure/_ccomp.pxd} | 0 .../ccomp.pyx => measure/_ccomp.pyx} | 0 skimage/measure/setup.py | 3 + skimage/morphology/_label.py | 71 +++++++++++++++++++ skimage/morphology/setup.py | 3 - skimage/segmentation/_felzenszwalb_cy.pyx | 2 +- 7 files changed, 76 insertions(+), 5 deletions(-) rename skimage/{morphology/ccomp.pxd => measure/_ccomp.pxd} (100%) rename skimage/{morphology/ccomp.pyx => measure/_ccomp.pyx} (100%) create mode 100644 skimage/morphology/_label.py diff --git a/skimage/measure/__init__.py b/skimage/measure/__init__.py index f7c0656a..ff8a83fc 100755 --- a/skimage/measure/__init__.py +++ b/skimage/measure/__init__.py @@ -8,7 +8,7 @@ from ._moments import moments, moments_central, moments_normalized, moments_hu from .profile import profile_line from .fit import LineModel, CircleModel, EllipseModel, ransac from .block import block_reduce -from ..morphology.ccomp import label +from ._ccomp import label __all__ = ['find_contours', diff --git a/skimage/morphology/ccomp.pxd b/skimage/measure/_ccomp.pxd similarity index 100% rename from skimage/morphology/ccomp.pxd rename to skimage/measure/_ccomp.pxd diff --git a/skimage/morphology/ccomp.pyx b/skimage/measure/_ccomp.pyx similarity index 100% rename from skimage/morphology/ccomp.pyx rename to skimage/measure/_ccomp.pyx diff --git a/skimage/measure/setup.py b/skimage/measure/setup.py index af8a4be1..0fab0787 100644 --- a/skimage/measure/setup.py +++ b/skimage/measure/setup.py @@ -12,10 +12,13 @@ def configuration(parent_package='', top_path=None): config = Configuration('measure', parent_package, top_path) config.add_data_dir('tests') + cython(['_ccomp.pyx'], working_path=base_path) cython(['_find_contours_cy.pyx'], working_path=base_path) cython(['_moments.pyx'], working_path=base_path) cython(['_marching_cubes_cy.pyx'], working_path=base_path) + config.add_extension('_ccomp', sources=['_ccomp.c'], + include_dirs=[get_numpy_include_dirs()]) config.add_extension('_find_contours_cy', sources=['_find_contours_cy.c'], include_dirs=[get_numpy_include_dirs()]) config.add_extension('_moments', sources=['_moments.c'], diff --git a/skimage/morphology/_label.py b/skimage/morphology/_label.py new file mode 100644 index 00000000..0f027adf --- /dev/null +++ b/skimage/morphology/_label.py @@ -0,0 +1,71 @@ +__all__ = ['label'] + +from ..measure._ccomp import label as _label +from skimage._shared.utils import deprecated + +@deprecated('skimage.measure.label') +def label(input, neighbors=8, background=None, return_num=False): + """Label connected regions of an integer array. + + Two pixels are connected when they are neighbors and have the same value. + They can be neighbors either in a 4- or 8-connected sense:: + + 4-connectivity 8-connectivity + + [ ] [ ] [ ] [ ] + | \ | / + [ ]--[ ]--[ ] [ ]--[ ]--[ ] + | / | \\ + [ ] [ ] [ ] [ ] + + Parameters + ---------- + input : ndarray of dtype int + Image to label. + neighbors : {4, 8}, int + Whether to use 4- or 8-connectivity. + background : int + Consider all pixels with this value as background pixels, and label + them as -1. (Note: background pixels will be labeled as 0 starting with + version 0.12). + return_num : bool + Whether to return the number of assigned labels. + + Returns + ------- + labels : ndarray of dtype int + Labeled array, where all connected regions are assigned the + same integer value. + num : int, optional + Number of labels, which equals the maximum label index and is only + returned if return_num is `True`. + + Examples + -------- + >>> x = np.eye(3).astype(int) + >>> print(x) + [[1 0 0] + [0 1 0] + [0 0 1]] + + >>> print(m.label(x, neighbors=4)) + [[0 1 1] + [2 3 1] + [2 2 4]] + + >>> print(m.label(x, neighbors=8)) + [[0 1 1] + [1 0 1] + [1 1 0]] + + >>> x = np.array([[1, 0, 0], + ... [1, 1, 5], + ... [0, 0, 0]]) + + >>> print(m.label(x, background=0)) + [[ 0 -1 -1] + [ 0 0 1] + [-1 -1 -1]] + + """ + return _label(input, neighbors, background, return_num) diff --git a/skimage/morphology/setup.py b/skimage/morphology/setup.py index 1936377b..f0f69764 100644 --- a/skimage/morphology/setup.py +++ b/skimage/morphology/setup.py @@ -12,7 +12,6 @@ def configuration(parent_package='', top_path=None): config = Configuration('morphology', parent_package, top_path) config.add_data_dir('tests') - cython(['ccomp.pyx'], working_path=base_path) cython(['cmorph.pyx'], working_path=base_path) cython(['_watershed.pyx'], working_path=base_path) cython(['_skeletonize_cy.pyx'], working_path=base_path) @@ -20,8 +19,6 @@ def configuration(parent_package='', top_path=None): cython(['_convex_hull.pyx'], working_path=base_path) cython(['_greyreconstruct.pyx'], working_path=base_path) - config.add_extension('ccomp', sources=['ccomp.c'], - include_dirs=[get_numpy_include_dirs()]) config.add_extension('cmorph', sources=['cmorph.c'], include_dirs=[get_numpy_include_dirs()]) config.add_extension('_watershed', sources=['_watershed.c'], diff --git a/skimage/segmentation/_felzenszwalb_cy.pyx b/skimage/segmentation/_felzenszwalb_cy.pyx index c7961084..80afaedb 100644 --- a/skimage/segmentation/_felzenszwalb_cy.pyx +++ b/skimage/segmentation/_felzenszwalb_cy.pyx @@ -7,7 +7,7 @@ import scipy cimport cython cimport numpy as cnp -from skimage.morphology.ccomp cimport find_root, join_trees +from skimage.measure._ccomp cimport find_root, join_trees from ..util import img_as_float