diff --git a/bento.info b/bento.info index d0891272..564f1f5a 100644 --- a/bento.info +++ b/bento.info @@ -37,12 +37,12 @@ Library: skimage.io._plugins, skimage.measure, skimage.morphology, skimage.scripts, skimage.restoration, skimage.segmentation, skimage.transform, skimage.util - Extension: skimage.morphology._pnpoly - Sources: - skimage/morphology/_pnpoly.pyx Extension: skimage.io._plugins._colormixer Sources: skimage/io/_plugins/_colormixer.pyx + Extension: skimage.measure._pnpoly + Sources: + skimage/measure/_pnpoly.pyx Extension: skimage.measure._find_contours_cy Sources: skimage/measure/_find_contours_cy.pyx diff --git a/doc/logo/scipy_logo.py b/doc/logo/scipy_logo.py index c57cd95b..bc145069 100644 --- a/doc/logo/scipy_logo.py +++ b/doc/logo/scipy_logo.py @@ -3,11 +3,11 @@ Code used to trace Scipy logo. """ import numpy as np import matplotlib.pyplot as plt -import matplotlib.nxutils as nx from skimage import io from skimage import data +from skimage.measure import points_in_poly class SymmetricAnchorPoint(object): """Anchor point in a parametric curve with symmetric handles @@ -211,7 +211,7 @@ class ScipyLogo(object): y_img, x_img = np.mgrid[:h, :w] xy_points = np.column_stack((x_img.flat, y_img.flat)) - mask = nx.points_inside_poly(xy_points, xy_poly) + mask = points_in_poly(xy_points, xy_poly) return mask.reshape((h, w)) diff --git a/skimage/measure/__init__.py b/skimage/measure/__init__.py index e07b9789..9731d6da 100755 --- a/skimage/measure/__init__.py +++ b/skimage/measure/__init__.py @@ -4,6 +4,7 @@ from ._marching_cubes import (marching_cubes, mesh_surface_area, from ._regionprops import regionprops, perimeter from ._structural_similarity import structural_similarity from ._polygon import approximate_polygon, subdivide_polygon +from ._pnpoly import points_in_poly, grid_points_in_poly from ._moments import moments, moments_central, moments_normalized, moments_hu from .profile import profile_line from .fit import LineModel, CircleModel, EllipseModel, ransac @@ -30,4 +31,6 @@ __all__ = ['find_contours', 'mesh_surface_area', 'correct_mesh_orientation', 'profile_line', - 'label'] + 'label', + 'points_in_poly', + 'grid_points_in_poly'] diff --git a/skimage/morphology/_pnpoly.pyx b/skimage/measure/_pnpoly.pyx similarity index 93% rename from skimage/morphology/_pnpoly.pyx rename to skimage/measure/_pnpoly.pyx index 12b48e5d..90d990ce 100644 --- a/skimage/morphology/_pnpoly.pyx +++ b/skimage/measure/_pnpoly.pyx @@ -8,7 +8,7 @@ cimport numpy as cnp from skimage._shared.geometry cimport point_in_polygon, points_in_polygon -def grid_points_inside_poly(shape, verts): +def grid_points_in_poly(shape, verts): """Test whether points on a specified grid are inside a polygon. For each ``(r, c)`` coordinate on a grid, i.e. ``(0, 0)``, ``(0, 1)`` etc., @@ -23,6 +23,10 @@ def grid_points_inside_poly(shape, verts): or anti-clockwise. The first point may (but does not need to be) duplicated. + See Also + -------- + points_in_poly + Returns ------- mask : (M, N) ndarray of bool @@ -50,7 +54,7 @@ def grid_points_inside_poly(shape, verts): return out.view(bool) -def points_inside_poly(points, verts): +def points_in_poly(points, verts): """Test whether points lie inside a polygon. Parameters @@ -61,6 +65,10 @@ def points_inside_poly(points, verts): Vertices of the polygon, sorted either clockwise or anti-clockwise. The first point may (but does not need to be) duplicated. + See Also + -------- + grid_points_in_poly + Returns ------- mask : (N,) array of bool diff --git a/skimage/measure/setup.py b/skimage/measure/setup.py index 0fab0787..9fce3cf0 100644 --- a/skimage/measure/setup.py +++ b/skimage/measure/setup.py @@ -16,6 +16,7 @@ def configuration(parent_package='', top_path=None): 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) + cython(['_pnpoly.pyx'], working_path=base_path) config.add_extension('_ccomp', sources=['_ccomp.c'], include_dirs=[get_numpy_include_dirs()]) @@ -26,6 +27,8 @@ def configuration(parent_package='', top_path=None): config.add_extension('_marching_cubes_cy', sources=['_marching_cubes_cy.c'], include_dirs=[get_numpy_include_dirs()]) + config.add_extension('_pnpoly', sources=['_pnpoly.c'], + include_dirs=[get_numpy_include_dirs(), '../_shared']) return config diff --git a/skimage/morphology/tests/test_pnpoly.py b/skimage/measure/tests/test_pnpoly.py similarity index 51% rename from skimage/morphology/tests/test_pnpoly.py rename to skimage/measure/tests/test_pnpoly.py index da468b08..e98b355f 100644 --- a/skimage/morphology/tests/test_pnpoly.py +++ b/skimage/measure/tests/test_pnpoly.py @@ -1,8 +1,7 @@ import numpy as np from numpy.testing import assert_array_equal -from skimage.morphology._pnpoly import points_inside_poly, \ - grid_points_inside_poly +from skimage.measure import points_in_poly, grid_points_in_poly class test_npnpoly(): @@ -11,29 +10,29 @@ class test_npnpoly(): [0, 1], [1, 1], [1, 0]]) - assert(points_inside_poly([[0.5, 0.5]], v)[0]) - assert(not points_inside_poly([[-0.1, 0.1]], v)[0]) + assert(points_in_poly([[0.5, 0.5]], v)[0]) + assert(not points_in_poly([[-0.1, 0.1]], v)[0]) def test_triangle(self): v = np.array([[0, 0], [1, 0], [0.5, 0.75]]) - assert(points_inside_poly([[0.5, 0.7]], v)[0]) - assert(not points_inside_poly([[0.5, 0.76]], v)[0]) - assert(not points_inside_poly([[0.7, 0.5]], v)[0]) + assert(points_in_poly([[0.5, 0.7]], v)[0]) + assert(not points_in_poly([[0.5, 0.76]], v)[0]) + assert(not points_in_poly([[0.7, 0.5]], v)[0]) def test_type(self): - assert(points_inside_poly([[0, 0]], [[0, 0]]).dtype == np.bool) + assert(points_in_poly([[0, 0]], [[0, 0]]).dtype == np.bool) -def test_grid_points_inside_poly(): +def test_grid_points_in_poly(): v = np.array([[0, 0], [5, 0], [5, 5]]) expected = np.tril(np.ones((5, 5), dtype=bool)) - assert_array_equal(grid_points_inside_poly((5, 5), v), + assert_array_equal(grid_points_in_poly((5, 5), v), expected) if __name__ == "__main__": diff --git a/skimage/morphology/convex_hull.py b/skimage/morphology/convex_hull.py index c5b9eb3f..edc49d4b 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 ._pnpoly import grid_points_inside_poly +from ..measure import grid_points_in_poly from ._convex_hull import possible_hull from ..measure._label import label from skimage.util import unique_rows @@ -72,7 +72,7 @@ def convex_hull_image(image): # For each pixel coordinate, check whether that pixel # lies inside the convex hull - mask = grid_points_inside_poly(image.shape[:2], v) + mask = grid_points_in_poly(image.shape[:2], v) return mask diff --git a/skimage/morphology/setup.py b/skimage/morphology/setup.py index f0f69764..de1a8794 100644 --- a/skimage/morphology/setup.py +++ b/skimage/morphology/setup.py @@ -15,7 +15,6 @@ def configuration(parent_package='', top_path=None): cython(['cmorph.pyx'], working_path=base_path) cython(['_watershed.pyx'], working_path=base_path) cython(['_skeletonize_cy.pyx'], working_path=base_path) - cython(['_pnpoly.pyx'], working_path=base_path) cython(['_convex_hull.pyx'], working_path=base_path) cython(['_greyreconstruct.pyx'], working_path=base_path) @@ -25,8 +24,6 @@ def configuration(parent_package='', top_path=None): include_dirs=[get_numpy_include_dirs()]) config.add_extension('_skeletonize_cy', sources=['_skeletonize_cy.c'], include_dirs=[get_numpy_include_dirs()]) - config.add_extension('_pnpoly', sources=['_pnpoly.c'], - include_dirs=[get_numpy_include_dirs(), '../_shared']) config.add_extension('_convex_hull', sources=['_convex_hull.c'], include_dirs=[get_numpy_include_dirs()]) config.add_extension('_greyreconstruct', sources=['_greyreconstruct.c'],