Merge pull request #1123 from stefanv/pnpoly

Expose point_in_poly and move to measure module
This commit is contained in:
Johannes Schönberger
2014-09-28 09:20:29 -04:00
8 changed files with 33 additions and 23 deletions
+4 -1
View File
@@ -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']
@@ -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
+3
View File
@@ -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
@@ -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__":
+2 -2
View File
@@ -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
-3
View File
@@ -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'],