From 1a598be98e5523b186bab30373f30be1fd086562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Tue, 17 Nov 2015 10:07:29 -0500 Subject: [PATCH 1/7] Fix region props deprecation problem with label function --- skimage/measure/_label.py | 2 +- skimage/measure/_regionprops.py | 4 ++-- skimage/measure/tests/test_regionprops.py | 11 ++++------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/skimage/measure/_label.py b/skimage/measure/_label.py index e3ac6034..9dcefed4 100644 --- a/skimage/measure/_label.py +++ b/skimage/measure/_label.py @@ -1,7 +1,7 @@ from ._ccomp import label as _label def label(input, neighbors=None, background=None, return_num=False, - connectivity=None): + connectivity=None): return _label(input, neighbors, background, return_num, connectivity) label.__doc__ = _label.__doc__ diff --git a/skimage/measure/_regionprops.py b/skimage/measure/_regionprops.py index 1655ec61..f38fda22 100644 --- a/skimage/measure/_regionprops.py +++ b/skimage/measure/_regionprops.py @@ -157,7 +157,7 @@ class _RegionProperties(object): @property def euler_number(self): euler_array = self.filled_image != self.image - _, num = label(euler_array, neighbors=8, return_num=True) + _, num = label(euler_array, neighbors=8, return_num=True, background=-1) return -num + 1 @property @@ -473,7 +473,7 @@ def regionprops(label_image, intensity_image=None, cache=True): Examples -------- >>> from skimage import data, util - >>> from skimage.morphology import label + >>> from skimage.measure import label >>> img = util.img_as_ubyte(data.coins()) > 110 >>> label_img = label(img, connectivity=img.ndim) >>> props = regionprops(label_img) diff --git a/skimage/measure/tests/test_regionprops.py b/skimage/measure/tests/test_regionprops.py index 514b84d3..6865818e 100644 --- a/skimage/measure/tests/test_regionprops.py +++ b/skimage/measure/tests/test_regionprops.py @@ -128,14 +128,12 @@ def test_equiv_diameter(): def test_euler_number(): - with expected_warnings(['`background`|CObject type']): - en = regionprops(SAMPLE)[0].euler_number + en = regionprops(SAMPLE)[0].euler_number assert en == 0 SAMPLE_mod = SAMPLE.copy() SAMPLE_mod[7, -3] = 0 - with expected_warnings(['`background`|CObject type']): - en = regionprops(SAMPLE_mod)[0].euler_number + en = regionprops(SAMPLE_mod)[0].euler_number assert en == -1 @@ -374,9 +372,8 @@ def test_equals(): r2 = regions[0] r3 = regions[1] - with expected_warnings(['`background`|CObject type']): - assert_equal(r1 == r2, True, "Same regionprops are not equal") - assert_equal(r1 != r3, True, "Different regionprops are equal") + assert_equal(r1 == r2, True, "Same regionprops are not equal") + assert_equal(r1 != r3, True, "Different regionprops are equal") if __name__ == "__main__": From 3437eb89b0def702222a14d5f488ff6127cd6bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Tue, 17 Nov 2015 10:09:42 -0500 Subject: [PATCH 2/7] Fix deprecated filter module import --- skimage/filters/_gabor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/skimage/filters/_gabor.py b/skimage/filters/_gabor.py index 211571f9..8bb7b61b 100644 --- a/skimage/filters/_gabor.py +++ b/skimage/filters/_gabor.py @@ -56,7 +56,7 @@ def gabor_kernel(frequency, theta=0, bandwidth=1, sigma_x=None, sigma_y=None, Examples -------- - >>> from skimage.filter import gabor_kernel + >>> from skimage.filters import gabor_kernel >>> from skimage import io >>> from matplotlib import pyplot as plt # doctest: +SKIP @@ -148,7 +148,7 @@ def gabor(image, frequency, theta=0, bandwidth=1, sigma_x=None, Examples -------- - >>> from skimage.filter import gabor + >>> from skimage.filters import gabor >>> from skimage import data, io >>> from matplotlib import pyplot as plt # doctest: +SKIP From 1278b02161b7b1cf037e3c892b4513809f935795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Tue, 17 Nov 2015 10:19:09 -0500 Subject: [PATCH 3/7] Fix circular import between regionprops and convex_hull_image --- skimage/measure/_regionprops.py | 2 +- skimage/morphology/convex_hull.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/skimage/measure/_regionprops.py b/skimage/measure/_regionprops.py index f38fda22..38d06ba3 100644 --- a/skimage/measure/_regionprops.py +++ b/skimage/measure/_regionprops.py @@ -5,6 +5,7 @@ from scipy import ndimage as ndi from ._label import label from . import _moments +from ..morphology.convex_hull import convex_hull_image __all__ = ['regionprops', 'perimeter'] @@ -134,7 +135,6 @@ class _RegionProperties(object): @_cached_property def convex_image(self): - from ..morphology.convex_hull import convex_hull_image return convex_hull_image(self.image) @property diff --git a/skimage/morphology/convex_hull.py b/skimage/morphology/convex_hull.py index 5926e1e0..43206c32 100644 --- a/skimage/morphology/convex_hull.py +++ b/skimage/morphology/convex_hull.py @@ -1,7 +1,7 @@ __all__ = ['convex_hull_image', 'convex_hull_object'] import numpy as np -from ..measure import grid_points_in_poly +from ..measure._pnpoly import grid_points_in_poly from ._convex_hull import possible_hull from ..measure._label import label from ..util import unique_rows From 6e644c4aa6726040d08a19cc00fe59b3c9938591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Tue, 17 Nov 2015 10:22:44 -0500 Subject: [PATCH 4/7] Remove single author from header, fix typo Functions in this file are from multiple authors, the original author is attributed in the contributors section and the Git history. --- CONTRIBUTORS.txt | 3 +++ skimage/morphology/selem.py | 12 ++++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index bc58df84..c94755d8 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -215,3 +215,6 @@ - Jim Fienup, Alexander Iacchetta In-depth review of sub-pixel shift registration + +- Damian Eads + Structuring elements in morphology module. diff --git a/skimage/morphology/selem.py b/skimage/morphology/selem.py index 53972cdd..8e516103 100644 --- a/skimage/morphology/selem.py +++ b/skimage/morphology/selem.py @@ -1,12 +1,8 @@ -""" -:author: Damian Eads, 2009 -:license: modified BSD -""" - import numpy as np from scipy import ndimage as ndi from .. import draw + def square(width, dtype=np.uint8): """Generates a flat, square-shaped structuring element. @@ -37,7 +33,7 @@ def rectangle(width, height, dtype=np.uint8): """Generates a flat, rectangular-shaped structuring element. Every pixel in the rectangle generated for a given width and given height - belongs to the neighboorhood. + belongs to the neighborhood. Parameters ---------- @@ -65,7 +61,7 @@ def diamond(radius, dtype=np.uint8): """Generates a flat, diamond-shaped structuring element. A pixel is part of the neighborhood (i.e. labeled 1) if - the city block/manhattan distance between it and the center of + the city block/Manhattan distance between it and the center of the neighborhood is no greater than radius. Parameters @@ -193,7 +189,7 @@ def octahedron(radius, dtype=np.uint8): This is the 3D equivalent of a diamond. A pixel is part of the neighborhood (i.e. labeled 1) if - the city block/manhattan distance between it and the center of + the city block/Manhattan distance between it and the center of the neighborhood is no greater than radius. Parameters From a63b746e6c3e121f03e2b8641393ddba9f730519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Tue, 17 Nov 2015 10:25:05 -0500 Subject: [PATCH 5/7] Move import test to top of function and import outside of function --- skimage/morphology/convex_hull.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/skimage/morphology/convex_hull.py b/skimage/morphology/convex_hull.py index 43206c32..ae395eac 100644 --- a/skimage/morphology/convex_hull.py +++ b/skimage/morphology/convex_hull.py @@ -6,6 +6,11 @@ from ._convex_hull import possible_hull from ..measure._label import label from ..util import unique_rows +try: + from scipy.spatial import Delaunay +except ImportError: + Delaunay = None + def convex_hull_image(image): """Compute the convex hull image of a binary image. @@ -29,6 +34,10 @@ def convex_hull_image(image): """ + if Delaunay is None: + raise ImportError("Could not import scipy.spatial.Delaunay, " + "only available in scipy >= 0.9.") + image = image.astype(bool) # Here we do an optimisation by choosing only pixels that are @@ -48,12 +57,6 @@ def convex_hull_image(image): # scipy.spatial.Delaunay, so we remove them. coords = unique_rows(coords_corners) - try: - from scipy.spatial import Delaunay - except ImportError: - raise ImportError('Could not import scipy.spatial, only available in ' - 'scipy >= 0.9.') - # Subtract offset offset = coords.mean(axis=0) coords -= offset From 9d3a7b4ecd30bdcb9768f4557a64e3230e6640bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Wed, 18 Nov 2015 08:58:01 -0500 Subject: [PATCH 6/7] Remove redundant type conversion --- skimage/morphology/convex_hull.py | 9 +++------ skimage/morphology/tests/test_convex_hull.py | 1 + 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/skimage/morphology/convex_hull.py b/skimage/morphology/convex_hull.py index ae395eac..bb9ca734 100644 --- a/skimage/morphology/convex_hull.py +++ b/skimage/morphology/convex_hull.py @@ -20,12 +20,12 @@ def convex_hull_image(image): Parameters ---------- - image : ndarray + image : (M, N) array Binary input image. This array is cast to bool before processing. Returns ------- - hull : ndarray of bool + hull : (M, N) array of bool Binary image with pixels in convex hull set to True. References @@ -38,12 +38,9 @@ def convex_hull_image(image): raise ImportError("Could not import scipy.spatial.Delaunay, " "only available in scipy >= 0.9.") - image = image.astype(bool) - # Here we do an optimisation by choosing only pixels that are # the starting or ending pixel of a row or column. This vastly - # limits the number of coordinates to examine for the virtual - # hull. + # limits the number of coordinates to examine for the virtual hull. coords = possible_hull(image.astype(np.uint8)) N = len(coords) diff --git a/skimage/morphology/tests/test_convex_hull.py b/skimage/morphology/tests/test_convex_hull.py index 67850cf2..c0cc954e 100644 --- a/skimage/morphology/tests/test_convex_hull.py +++ b/skimage/morphology/tests/test_convex_hull.py @@ -139,5 +139,6 @@ def test_object(): assert_raises(ValueError, convex_hull_object, image, 7) + if __name__ == "__main__": np.testing.run_module_suite() From ba3c0c02cd81344cb5a8d385e6e4fb97656a7ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Wed, 18 Nov 2015 09:02:02 -0500 Subject: [PATCH 7/7] Fix circular import loop --- skimage/measure/_regionprops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/measure/_regionprops.py b/skimage/measure/_regionprops.py index 38d06ba3..f38fda22 100644 --- a/skimage/measure/_regionprops.py +++ b/skimage/measure/_regionprops.py @@ -5,7 +5,6 @@ from scipy import ndimage as ndi from ._label import label from . import _moments -from ..morphology.convex_hull import convex_hull_image __all__ = ['regionprops', 'perimeter'] @@ -135,6 +134,7 @@ class _RegionProperties(object): @_cached_property def convex_image(self): + from ..morphology.convex_hull import convex_hull_image return convex_hull_image(self.image) @property