From 7152d5c3140980be31c7671c470e4136694aeb55 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Thu, 8 May 2014 17:49:47 +0200 Subject: [PATCH 1/8] Move label to measure module (with deprecation). Warn that background parameter will default to 0 in v0.12. --- TODO.txt | 9 +++++++ doc/source/api_changes.txt | 1 - skimage/measure/__init__.py | 4 ++- skimage/morphology/__init__.py | 3 +-- skimage/morphology/ccomp.pyx | 26 +++++++++++++++----- skimage/morphology/tests/test_ccomp.py | 34 +++++++++++++++----------- 6 files changed, 53 insertions(+), 24 deletions(-) diff --git a/TODO.txt b/TODO.txt index bec8efe6..47d4ec90 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,3 +1,12 @@ +Remember to list any API changes below in `doc/source/api_changes.txt`. + +Version 0.12 +------------ +- Change `label` to mark background as 0, not -1, which is consistent with + SciPy's labelling. +- Remove `skimage.morphology.label` from `skimage.morphology.__init__`--it now + lives in `skimage.measure.label`. + Version 0.11 ------------ * Remove deprecated `reverse_map` parameter of `skimage.transform.warp` diff --git a/doc/source/api_changes.txt b/doc/source/api_changes.txt index 527c9fb0..0271bec0 100644 --- a/doc/source/api_changes.txt +++ b/doc/source/api_changes.txt @@ -24,4 +24,3 @@ Version 0.3 - Remove ``as_grey``, ``dtype`` keyword from ImageCollection - Remove ``dtype`` from imread - Generalise ImageCollection to accept a load_func - diff --git a/skimage/measure/__init__.py b/skimage/measure/__init__.py index d76e7a67..f7c0656a 100755 --- a/skimage/measure/__init__.py +++ b/skimage/measure/__init__.py @@ -8,6 +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 __all__ = ['find_contours', @@ -28,4 +29,5 @@ __all__ = ['find_contours', 'marching_cubes', 'mesh_surface_area', 'correct_mesh_orientation', - 'profile_line'] + 'profile_line', + 'label'] diff --git a/skimage/morphology/__init__.py b/skimage/morphology/__init__.py index bee5ac13..5d2406e8 100644 --- a/skimage/morphology/__init__.py +++ b/skimage/morphology/__init__.py @@ -4,14 +4,13 @@ from .grey import (erosion, dilation, opening, closing, white_tophat, black_tophat) from .selem import (square, rectangle, diamond, disk, cube, octahedron, ball, octagon, star) -from .ccomp import label +from ._label import label from .watershed import watershed from ._skeletonize import skeletonize, medial_axis from .convex_hull import convex_hull_image, convex_hull_object from .greyreconstruct import reconstruction from .misc import remove_small_objects - __all__ = ['binary_erosion', 'binary_dilation', 'binary_opening', diff --git a/skimage/morphology/ccomp.pyx b/skimage/morphology/ccomp.pyx index 91e2611c..2d2f5b13 100644 --- a/skimage/morphology/ccomp.pyx +++ b/skimage/morphology/ccomp.pyx @@ -4,6 +4,7 @@ #cython: wraparound=False import numpy as np +import warnings cimport numpy as cnp @@ -82,7 +83,7 @@ cdef inline void link_bg(DTYPE_t *forest, DTYPE_t n, DTYPE_t *background_node): # Connected components search as described in Fiorio et al. -def label(input, DTYPE_t neighbors=8, DTYPE_t background=-1, return_num=False): +def label(input, DTYPE_t 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. @@ -104,7 +105,10 @@ def label(input, DTYPE_t neighbors=8, DTYPE_t background=-1, return_num=False): Whether to use 4- or 8-connectivity. background : int Consider all pixels with this value as background pixels, and label - them as -1. + 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 ------- @@ -157,17 +161,27 @@ def label(input, DTYPE_t neighbors=8, DTYPE_t background=-1, return_num=False): cdef DTYPE_t i, j + cdef DTYPE_t background_val + + if background is None: + background_val = -1 + warnings.warn(DeprecationWarning( + 'The default value for `background` will change to 0 in v0.12' + )) + else: + background_val = background + cdef DTYPE_t background_node = -999 if neighbors != 4 and neighbors != 8: raise ValueError('Neighbors must be either 4 or 8.') # Initialize the first row - if data[0, 0] == background: + if data[0, 0] == background_val: link_bg(forest_p, 0, &background_node) for j in range(1, cols): - if data[0, j] == background: + if data[0, j] == background_val: link_bg(forest_p, j, &background_node) if data[0, j] == data[0, j-1]: @@ -175,7 +189,7 @@ def label(input, DTYPE_t neighbors=8, DTYPE_t background=-1, return_num=False): for i in range(1, rows): # Handle the first column - if data[i, 0] == background: + if data[i, 0] == background_val: link_bg(forest_p, i * cols, &background_node) if data[i, 0] == data[i-1, 0]: @@ -186,7 +200,7 @@ def label(input, DTYPE_t neighbors=8, DTYPE_t background=-1, return_num=False): join_trees(forest_p, i*cols, (i-1)*cols + 1) for j in range(1, cols): - if data[i, j] == background: + if data[i, j] == background_val: link_bg(forest_p, i * cols + j, &background_node) if neighbors == 8: diff --git a/skimage/morphology/tests/test_ccomp.py b/skimage/morphology/tests/test_ccomp.py index 1169be85..34de8fb9 100644 --- a/skimage/morphology/tests/test_ccomp.py +++ b/skimage/morphology/tests/test_ccomp.py @@ -2,7 +2,7 @@ import numpy as np from numpy.testing import assert_array_equal, run_module_suite from skimage.morphology import label - +from warnings import catch_warnings class TestConnectedComponents: def setup(self): @@ -25,7 +25,9 @@ class TestConnectedComponents: def test_random(self): x = (np.random.random((20, 30)) * 5).astype(np.int) - labels = label(x) + with catch_warnings(DeprecationWarning): + labels = label(x) + n = labels.max() for i in range(n): values = x[labels == i] @@ -35,27 +37,29 @@ class TestConnectedComponents: x = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]) - assert_array_equal(label(x), - x) + with catch_warnings(DeprecationWarning): + assert_array_equal(label(x), x) def test_4_vs_8(self): x = np.array([[0, 1], [1, 0]], dtype=int) - assert_array_equal(label(x, 4), - [[0, 1], - [2, 3]]) - assert_array_equal(label(x, 8), - [[0, 1], - [1, 0]]) + with catch_warnings(DeprecationWarning): + assert_array_equal(label(x, 4), + [[0, 1], + [2, 3]]) + assert_array_equal(label(x, 8), + [[0, 1], + [1, 0]]) def test_background(self): x = np.array([[1, 0, 0], [1, 1, 5], [0, 0, 0]]) - assert_array_equal(label(x), [[0, 1, 1], - [0, 0, 2], - [3, 3, 3]]) + with catch_warnings(DeprecationWarning): + assert_array_equal(label(x), [[0, 1, 1], + [0, 0, 2], + [3, 3, 3]]) assert_array_equal(label(x, background=0), [[0, -1, -1], @@ -87,7 +91,9 @@ class TestConnectedComponents: [0, 0, 6], [5, 5, 5]]) - assert_array_equal(label(x, return_num=True)[1], 4) + with catch_warnings(DeprecationWarning): + assert_array_equal(label(x, return_num=True)[1], 4) + assert_array_equal(label(x, background=0, return_num=True)[1], 3) From 46829c6a33f37f850aa5a75f590a5f1cd61b67bb Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Thu, 8 May 2014 18:04:03 +0200 Subject: [PATCH 2/8] 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 From 5ba3ea421c8beb09f9596bac174892e90f05baba Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Thu, 8 May 2014 19:14:38 +0200 Subject: [PATCH 3/8] Fix imports and suppress deprecation warnings --- skimage/measure/_regionprops.py | 5 +++-- skimage/morphology/convex_hull.py | 2 +- skimage/morphology/tests/test_ccomp.py | 11 ++++++----- skimage/transform/hough_transform.py | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/skimage/measure/_regionprops.py b/skimage/measure/_regionprops.py index 88f7f843..1cf23685 100644 --- a/skimage/measure/_regionprops.py +++ b/skimage/measure/_regionprops.py @@ -4,8 +4,9 @@ from math import sqrt, atan2, pi as PI import numpy as np from scipy import ndimage -from skimage.morphology import convex_hull_image, label -from skimage.measure import _moments +from skimage.morphology import convex_hull_image +from ._ccomp import label +from . import _moments __all__ = ['regionprops', 'perimeter'] diff --git a/skimage/morphology/convex_hull.py b/skimage/morphology/convex_hull.py index 4d54498d..f335fefd 100644 --- a/skimage/morphology/convex_hull.py +++ b/skimage/morphology/convex_hull.py @@ -3,7 +3,7 @@ __all__ = ['convex_hull_image', 'convex_hull_object'] import numpy as np from ._pnpoly import grid_points_inside_poly from ._convex_hull import possible_hull -from skimage.morphology import label +from ..measure._ccomp import label from skimage.util import unique_rows diff --git a/skimage/morphology/tests/test_ccomp.py b/skimage/morphology/tests/test_ccomp.py index 34de8fb9..2ca5577f 100644 --- a/skimage/morphology/tests/test_ccomp.py +++ b/skimage/morphology/tests/test_ccomp.py @@ -3,6 +3,7 @@ from numpy.testing import assert_array_equal, run_module_suite from skimage.morphology import label from warnings import catch_warnings +from _shared.util import skimage_deprecation class TestConnectedComponents: def setup(self): @@ -25,7 +26,7 @@ class TestConnectedComponents: def test_random(self): x = (np.random.random((20, 30)) * 5).astype(np.int) - with catch_warnings(DeprecationWarning): + with catch_warnings(skimage_deprecation): labels = label(x) n = labels.max() @@ -37,13 +38,13 @@ class TestConnectedComponents: x = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]) - with catch_warnings(DeprecationWarning): + with catch_warnings(skimage_deprecation): assert_array_equal(label(x), x) def test_4_vs_8(self): x = np.array([[0, 1], [1, 0]], dtype=int) - with catch_warnings(DeprecationWarning): + with catch_warnings(skimage_deprecation): assert_array_equal(label(x, 4), [[0, 1], [2, 3]]) @@ -56,7 +57,7 @@ class TestConnectedComponents: [1, 1, 5], [0, 0, 0]]) - with catch_warnings(DeprecationWarning): + with catch_warnings(skimage_deprecation): assert_array_equal(label(x), [[0, 1, 1], [0, 0, 2], [3, 3, 3]]) @@ -91,7 +92,7 @@ class TestConnectedComponents: [0, 0, 6], [5, 5, 5]]) - with catch_warnings(DeprecationWarning): + with catch_warnings(skimage_deprecation): assert_array_equal(label(x, return_num=True)[1], 4) assert_array_equal(label(x, background=0, return_num=True)[1], 3) diff --git a/skimage/transform/hough_transform.py b/skimage/transform/hough_transform.py index 35a9cea8..cbb4caa6 100644 --- a/skimage/transform/hough_transform.py +++ b/skimage/transform/hough_transform.py @@ -71,7 +71,7 @@ def hough_line_peaks(hspace, angles, dists, min_distance=9, min_angle=10, hspace *= mask hspace_t = hspace > threshold - label_hspace = morphology.label(hspace_t) + label_hspace = measure.label(hspace_t) props = measure.regionprops(label_hspace) coords = np.array([np.round(p.centroid) for p in props], dtype=int) From 898f0d7fb508bb39630bd9f7fb54ae8dd288a9b8 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Thu, 8 May 2014 19:31:50 +0200 Subject: [PATCH 4/8] Update bento build --- bento.info | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bento.info b/bento.info index f1cbabc1..d3dfd440 100644 --- a/bento.info +++ b/bento.info @@ -64,9 +64,9 @@ Library: Extension: skimage.filter._ctmf Sources: skimage/filter/_ctmf.pyx - Extension: skimage.morphology.ccomp + Extension: skimage.measure._ccomp Sources: - skimage/morphology/ccomp.pyx + skimage/measure/_ccomp.pyx Extension: skimage.morphology._watershed Sources: skimage/morphology/_watershed.pyx From 1de102a885679fc8bcf70dcd4a64f81987eb7d9a Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Fri, 9 May 2014 02:53:48 +0200 Subject: [PATCH 5/8] Fix broken and circular imports --- skimage/measure/_regionprops.py | 2 +- skimage/morphology/tests/test_ccomp.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/skimage/measure/_regionprops.py b/skimage/measure/_regionprops.py index 1cf23685..bbf627a0 100644 --- a/skimage/measure/_regionprops.py +++ b/skimage/measure/_regionprops.py @@ -4,7 +4,7 @@ from math import sqrt, atan2, pi as PI import numpy as np from scipy import ndimage -from skimage.morphology import convex_hull_image +from ..morphology.convex_hull import convex_hull_image from ._ccomp import label from . import _moments diff --git a/skimage/morphology/tests/test_ccomp.py b/skimage/morphology/tests/test_ccomp.py index 2ca5577f..69b4b9e5 100644 --- a/skimage/morphology/tests/test_ccomp.py +++ b/skimage/morphology/tests/test_ccomp.py @@ -3,7 +3,7 @@ from numpy.testing import assert_array_equal, run_module_suite from skimage.morphology import label from warnings import catch_warnings -from _shared.util import skimage_deprecation +from skimage._shared.utils import skimage_deprecation class TestConnectedComponents: def setup(self): From 4da4ec5b89f276c662156346207c7ca785c17e88 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Fri, 9 May 2014 03:00:28 +0200 Subject: [PATCH 6/8] Mention which parameters to label are optional. Simplify label deprecation. --- skimage/measure/_ccomp.pyx | 6 ++-- skimage/morphology/_label.py | 67 +----------------------------------- 2 files changed, 4 insertions(+), 69 deletions(-) diff --git a/skimage/measure/_ccomp.pyx b/skimage/measure/_ccomp.pyx index 2d2f5b13..26b9645a 100644 --- a/skimage/measure/_ccomp.pyx +++ b/skimage/measure/_ccomp.pyx @@ -101,13 +101,13 @@ def label(input, DTYPE_t neighbors=8, background=None, return_num=False): ---------- input : ndarray of dtype int Image to label. - neighbors : {4, 8}, int + neighbors : {4, 8}, int, optional Whether to use 4- or 8-connectivity. - background : int + background : int, optional 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 + return_num : bool, optional Whether to return the number of assigned labels. Returns diff --git a/skimage/morphology/_label.py b/skimage/morphology/_label.py index 0f027adf..88312427 100644 --- a/skimage/morphology/_label.py +++ b/skimage/morphology/_label.py @@ -3,69 +3,4 @@ __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) +label = deprecated('skimage.measure.label')(_label) From 135965fbe4d991eb0ceb2e903af7335f0441618c Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sun, 25 May 2014 20:05:17 +0200 Subject: [PATCH 7/8] Avoid circular imports --- skimage/measure/__init__.py | 2 +- skimage/measure/_label.py | 6 ++++++ skimage/measure/_regionprops.py | 4 ++-- skimage/morphology/__init__.py | 6 +++++- skimage/morphology/_label.py | 6 ------ skimage/morphology/convex_hull.py | 2 +- 6 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 skimage/measure/_label.py delete mode 100644 skimage/morphology/_label.py diff --git a/skimage/measure/__init__.py b/skimage/measure/__init__.py index ff8a83fc..e07b9789 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 ._ccomp import label +from ._label import label __all__ = ['find_contours', diff --git a/skimage/measure/_label.py b/skimage/measure/_label.py new file mode 100644 index 00000000..47e8af74 --- /dev/null +++ b/skimage/measure/_label.py @@ -0,0 +1,6 @@ +from ._ccomp import label as _label + +def label(input, neighbors=8, background=None, return_num=False): + return _label(input, neighbors, background, return_num) + +label.__doc__ = _label.__doc__ diff --git a/skimage/measure/_regionprops.py b/skimage/measure/_regionprops.py index bbf627a0..848aa3a3 100644 --- a/skimage/measure/_regionprops.py +++ b/skimage/measure/_regionprops.py @@ -4,8 +4,7 @@ from math import sqrt, atan2, pi as PI import numpy as np from scipy import ndimage -from ..morphology.convex_hull import convex_hull_image -from ._ccomp import label +from ._label import label from . import _moments @@ -136,6 +135,7 @@ class _RegionProperties(object): @_cached_property def convex_image(self): + from ..morphology.convex_hull import convex_hull_image return convex_hull_image(self.image) @_cached_property diff --git a/skimage/morphology/__init__.py b/skimage/morphology/__init__.py index 5d2406e8..5b659093 100644 --- a/skimage/morphology/__init__.py +++ b/skimage/morphology/__init__.py @@ -4,13 +4,17 @@ from .grey import (erosion, dilation, opening, closing, white_tophat, black_tophat) from .selem import (square, rectangle, diamond, disk, cube, octahedron, ball, octagon, star) -from ._label import label from .watershed import watershed from ._skeletonize import skeletonize, medial_axis from .convex_hull import convex_hull_image, convex_hull_object from .greyreconstruct import reconstruction from .misc import remove_small_objects +from ..measure._label import label +from skimage._shared.utils import deprecated as _deprecated +label = _deprecated('skimage.measure.label')(label) + + __all__ = ['binary_erosion', 'binary_dilation', 'binary_opening', diff --git a/skimage/morphology/_label.py b/skimage/morphology/_label.py deleted file mode 100644 index 88312427..00000000 --- a/skimage/morphology/_label.py +++ /dev/null @@ -1,6 +0,0 @@ -__all__ = ['label'] - -from ..measure._ccomp import label as _label -from skimage._shared.utils import deprecated - -label = deprecated('skimage.measure.label')(_label) diff --git a/skimage/morphology/convex_hull.py b/skimage/morphology/convex_hull.py index f335fefd..c5b9eb3f 100644 --- a/skimage/morphology/convex_hull.py +++ b/skimage/morphology/convex_hull.py @@ -3,7 +3,7 @@ __all__ = ['convex_hull_image', 'convex_hull_object'] import numpy as np from ._pnpoly import grid_points_inside_poly from ._convex_hull import possible_hull -from ..measure._ccomp import label +from ..measure._label import label from skimage.util import unique_rows From c0be2ec505cd6c2150372a02403e543a9030f924 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Mon, 26 May 2014 01:21:58 +0200 Subject: [PATCH 8/8] Correctly apply catch_warnings() --- skimage/morphology/tests/test_ccomp.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/skimage/morphology/tests/test_ccomp.py b/skimage/morphology/tests/test_ccomp.py index 69b4b9e5..e934a5b7 100644 --- a/skimage/morphology/tests/test_ccomp.py +++ b/skimage/morphology/tests/test_ccomp.py @@ -26,7 +26,7 @@ class TestConnectedComponents: def test_random(self): x = (np.random.random((20, 30)) * 5).astype(np.int) - with catch_warnings(skimage_deprecation): + with catch_warnings(): labels = label(x) n = labels.max() @@ -38,13 +38,13 @@ class TestConnectedComponents: x = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]) - with catch_warnings(skimage_deprecation): + with catch_warnings(): assert_array_equal(label(x), x) def test_4_vs_8(self): x = np.array([[0, 1], [1, 0]], dtype=int) - with catch_warnings(skimage_deprecation): + with catch_warnings(): assert_array_equal(label(x, 4), [[0, 1], [2, 3]]) @@ -57,7 +57,7 @@ class TestConnectedComponents: [1, 1, 5], [0, 0, 0]]) - with catch_warnings(skimage_deprecation): + with catch_warnings(): assert_array_equal(label(x), [[0, 1, 1], [0, 0, 2], [3, 3, 3]]) @@ -92,7 +92,7 @@ class TestConnectedComponents: [0, 0, 6], [5, 5, 5]]) - with catch_warnings(skimage_deprecation): + with catch_warnings(): assert_array_equal(label(x, return_num=True)[1], 4) assert_array_equal(label(x, background=0, return_num=True)[1], 3)