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/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 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__": diff --git a/skimage/morphology/convex_hull.py b/skimage/morphology/convex_hull.py index 5926e1e0..bb9ca734 100644 --- a/skimage/morphology/convex_hull.py +++ b/skimage/morphology/convex_hull.py @@ -1,11 +1,16 @@ __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 +try: + from scipy.spatial import Delaunay +except ImportError: + Delaunay = None + def convex_hull_image(image): """Compute the convex hull image of a binary image. @@ -15,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 @@ -29,12 +34,13 @@ def convex_hull_image(image): """ - image = image.astype(bool) + if Delaunay is None: + raise ImportError("Could not import scipy.spatial.Delaunay, " + "only available in scipy >= 0.9.") # 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) @@ -48,12 +54,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 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 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()