Merge pull request #1846 from arokem/hull-docs

DOC: Small one. The input to this one needs to be 2D.
This commit is contained in:
Emmanuelle Gouillart
2015-12-24 10:34:00 +01:00
2 changed files with 26 additions and 14 deletions
+8 -3
View File
@@ -1,11 +1,12 @@
__all__ = ['convex_hull_image', 'convex_hull_object']
"""Convex Hull."""
import numpy as np
from ..measure._pnpoly import grid_points_in_poly
from ._convex_hull import possible_hull
from ..measure._label import label
from ..util import unique_rows
__all__ = ['convex_hull_image', 'convex_hull_object']
try:
from scipy.spatial import Delaunay
except ImportError:
@@ -33,6 +34,8 @@ def convex_hull_image(image):
.. [1] http://blogs.mathworks.com/steve/2011/10/04/binary-image-convex-hull-algorithm-notes/
"""
if image.ndim > 2:
raise ValueError("Input must be a 2D image")
if Delaunay is None:
raise ImportError("Could not import scipy.spatial.Delaunay, "
@@ -85,7 +88,7 @@ def convex_hull_object(image, neighbors=8):
Parameters
----------
image : ndarray
image : (M, N) array
Binary input image.
neighbors : {4, 8}, int
Whether to use 4- or 8-connectivity.
@@ -104,6 +107,8 @@ def convex_hull_object(image, neighbors=8):
convex_hull_image separately on each object.
"""
if image.ndim > 2:
raise ValueError("Input must be a 2D image")
if neighbors != 4 and neighbors != 8:
raise ValueError('Neighbors must be either 4 or 8.')
+18 -11
View File
@@ -31,20 +31,24 @@ def test_basic():
assert_array_equal(convex_hull_image(image), expected)
# Test that an error is raised on passing a 3D image:
image3d = np.empty((5, 5, 5))
assert_raises(ValueError, convex_hull_image, image3d)
@skipif(not scipy_spatial)
def test_qhull_offset_example():
nonzeros = (([1367, 1368, 1368, 1368, 1369, 1369, 1369, 1369, 1369, 1370, 1370,
1370, 1370, 1370, 1370, 1370, 1371, 1371, 1371, 1371, 1371, 1371,
1371, 1371, 1371, 1372, 1372, 1372, 1372, 1372, 1372, 1372, 1372,
1372, 1373, 1373, 1373, 1373, 1373, 1373, 1373, 1373, 1373, 1374,
1374, 1374, 1374, 1374, 1374, 1374, 1375, 1375, 1375, 1375, 1375,
1376, 1376, 1376, 1377]),
([151, 150, 151, 152, 149, 150, 151, 152, 153, 148, 149, 150, 151,
152, 153, 154, 147, 148, 149, 150, 151, 152, 153, 154, 155, 146,
147, 148, 149, 150, 151, 152, 153, 154, 146, 147, 148, 149, 150,
151, 152, 153, 154, 147, 148, 149, 150, 151, 152, 153, 148, 149,
150, 151, 152, 149, 150, 151, 150]))
nonzeros = (([1367, 1368, 1368, 1368, 1369, 1369, 1369, 1369, 1369, 1370,
1370, 1370, 1370, 1370, 1370, 1370, 1371, 1371, 1371, 1371,
1371, 1371, 1371, 1371, 1371, 1372, 1372, 1372, 1372, 1372,
1372, 1372, 1372, 1372, 1373, 1373, 1373, 1373, 1373, 1373,
1373, 1373, 1373, 1374, 1374, 1374, 1374, 1374, 1374, 1374,
1375, 1375, 1375, 1375, 1375, 1376, 1376, 1376, 1377]),
([151, 150, 151, 152, 149, 150, 151, 152, 153, 148, 149, 150,
151, 152, 153, 154, 147, 148, 149, 150, 151, 152, 153, 154,
155, 146, 147, 148, 149, 150, 151, 152, 153, 154, 146, 147,
148, 149, 150, 151, 152, 153, 154, 147, 148, 149, 150, 151,
152, 153, 148, 149, 150, 151, 152, 149, 150, 151, 150]))
image = np.zeros((1392, 1040), dtype=bool)
image[nonzeros] = True
expected = image.copy()
@@ -139,6 +143,9 @@ def test_object():
assert_raises(ValueError, convex_hull_object, image, 7)
# Test that an error is raised on passing a 3D image:
image3d = np.empty((5, 5, 5))
assert_raises(ValueError, convex_hull_object, image3d)
if __name__ == "__main__":
np.testing.run_module_suite()