From add4b51db7fb2d9adc9d21bc43d57a62c5b14380 Mon Sep 17 00:00:00 2001 From: Jeremy Metz Date: Fri, 31 Jan 2014 13:46:28 +0000 Subject: [PATCH 1/4] QH6228 Bug fix - remove offset from coords --- skimage/morphology/convex_hull.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/skimage/morphology/convex_hull.py b/skimage/morphology/convex_hull.py index 1a26b842..6fc08097 100644 --- a/skimage/morphology/convex_hull.py +++ b/skimage/morphology/convex_hull.py @@ -54,6 +54,10 @@ def convex_hull_image(image): raise ImportError('Could not import scipy.spatial, only available in ' 'scipy >= 0.9.') + # Subtract offset + offset = coords.mean(axis=0) + coords -= offset + # Find the convex hull chull = Delaunay(coords).convex_hull v = coords[np.unique(chull)] @@ -63,6 +67,9 @@ def convex_hull_image(image): angles = np.arctan2(v_centred[:, 0], v_centred[:, 1]) v = v[np.argsort(angles)] + # Add back offset + v += offset + # For each pixel coordinate, check whether that pixel # lies inside the convex hull mask = grid_points_inside_poly(image.shape[:2], v) From 920c3efb832c46c07135e3b5f98682d37a49433b Mon Sep 17 00:00:00 2001 From: Jeremy Metz Date: Sat, 1 Feb 2014 16:17:53 +0000 Subject: [PATCH 2/4] Added new convex_hull_image qhull test --- skimage/morphology/tests/test_convex_hull.py | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/skimage/morphology/tests/test_convex_hull.py b/skimage/morphology/tests/test_convex_hull.py index ee3b6bfa..d319662e 100644 --- a/skimage/morphology/tests/test_convex_hull.py +++ b/skimage/morphology/tests/test_convex_hull.py @@ -32,6 +32,28 @@ def test_basic(): assert_array_equal(convex_hull_image(image), expected) +@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])) + + image = np.zeros((1392, 1040), dtype=bool) + image[ nonzeros ] = True + + expected = image.copy() + + assert_array_equal(convex_hull_image(image), expected) + + @skipif(not scipy_spatial) def test_pathological_qhull_example(): image = np.array( From 0136fd5915d3d659a8c9f60e35a7bb6aa8b51c57 Mon Sep 17 00:00:00 2001 From: Jeremy Metz Date: Sat, 1 Feb 2014 20:30:39 +0000 Subject: [PATCH 3/4] Removed trailing whitespaces --- skimage/morphology/convex_hull.py | 6 +++--- skimage/morphology/tests/test_convex_hull.py | 9 +++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/skimage/morphology/convex_hull.py b/skimage/morphology/convex_hull.py index 6fc08097..4d54498d 100644 --- a/skimage/morphology/convex_hull.py +++ b/skimage/morphology/convex_hull.py @@ -54,10 +54,10 @@ def convex_hull_image(image): raise ImportError('Could not import scipy.spatial, only available in ' 'scipy >= 0.9.') - # Subtract offset + # Subtract offset offset = coords.mean(axis=0) coords -= offset - + # Find the convex hull chull = Delaunay(coords).convex_hull v = coords[np.unique(chull)] @@ -67,7 +67,7 @@ def convex_hull_image(image): angles = np.arctan2(v_centred[:, 0], v_centred[:, 1]) v = v[np.argsort(angles)] - # Add back offset + # Add back offset v += offset # For each pixel coordinate, check whether that pixel diff --git a/skimage/morphology/tests/test_convex_hull.py b/skimage/morphology/tests/test_convex_hull.py index d319662e..ad7f57a7 100644 --- a/skimage/morphology/tests/test_convex_hull.py +++ b/skimage/morphology/tests/test_convex_hull.py @@ -45,15 +45,12 @@ def test_qhull_offset_example(): 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() - + image[ nonzeros ] = True + expected = image.copy() assert_array_equal(convex_hull_image(image), expected) - + @skipif(not scipy_spatial) def test_pathological_qhull_example(): image = np.array( From ef779d158852a8645beaf46ad0681f04881dd4c8 Mon Sep 17 00:00:00 2001 From: Jeremy Metz Date: Sun, 2 Feb 2014 12:40:37 +0000 Subject: [PATCH 4/4] Fixed PEP8 spaces --- skimage/morphology/tests/test_convex_hull.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skimage/morphology/tests/test_convex_hull.py b/skimage/morphology/tests/test_convex_hull.py index ad7f57a7..67850cf2 100644 --- a/skimage/morphology/tests/test_convex_hull.py +++ b/skimage/morphology/tests/test_convex_hull.py @@ -46,7 +46,7 @@ def test_qhull_offset_example(): 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 + image[nonzeros] = True expected = image.copy() assert_array_equal(convex_hull_image(image), expected)