From 88a269c282aa44e7ada8fa611801eb153c3b0005 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Mon, 29 Sep 2014 01:14:57 +0200 Subject: [PATCH 01/13] Add polygon perimiter drawing --- skimage/_shared/_geometry.py | 54 +++++++++++++++++ skimage/_shared/tests/test_geometry.py | 75 ++++++++++++++++++++++++ skimage/draw/__init__.py | 2 +- skimage/draw/draw.py | 81 ++++++++++++++++++++++++++ skimage/draw/tests/test_draw.py | 33 ++++++++++- 5 files changed, 243 insertions(+), 2 deletions(-) create mode 100644 skimage/_shared/_geometry.py create mode 100644 skimage/_shared/tests/test_geometry.py diff --git a/skimage/_shared/_geometry.py b/skimage/_shared/_geometry.py new file mode 100644 index 00000000..602692cb --- /dev/null +++ b/skimage/_shared/_geometry.py @@ -0,0 +1,54 @@ +__all__ = ['polygon_clip', 'polygon_area'] + +import numpy as np + + +def polygon_clip(rr, cc, r0, c0, r1, c1): + """Clip a polygon to the given bounding box. + + Parameters + ---------- + yp, xp : (N,) ndarray of double + Row and column coordinates of the polygon. + ytop, xleft, ybottom, xright : double + Coordinates of the bounding box. Note that the following + must hold true: ``x_left < x_right`` and ``y_top < y_bottom``. + + Returns + ------- + y_clipped, x_clipped : (M,) ndarray of double + Coordinates of clipped polygon. + + Notes + ----- + The algorithm is a translation of the Pascal code found in [1]_ and + includes fixes from Anti-Grain Geometry v2.4. + + References + ---------- + .. [1] You-Dong Liang and Brian A. Barsky, + An Analysis and Algorithm for Polygon Clipping, + Communications of the ACM, Vol 26, No 11, November 1983. + + """ + from matplotlib import path, transforms + + poly = path.Path(np.vstack((rr, cc)).T, closed=True) + clip_rect = transforms.Bbox([[r0, c0], [r1, c1]]) + + poly_clipped = poly.clip_to_bbox(clip_rect).to_polygons()[0] + + return poly_clipped[:, 0], poly_clipped[:, 1] + + +def polygon_area(py, px): + """Compute the area of a polygon. + + Parameters + ---------- + py, px : (N,) array of float + Polygon coordinates. + """ + py = np.asarray(py) + px = np.asarray(px) + return 0.5 * np.abs(np.sum((px[:-1] * py[1:]) - (px[1:] * py[:-1]))) diff --git a/skimage/_shared/tests/test_geometry.py b/skimage/_shared/tests/test_geometry.py new file mode 100644 index 00000000..7466d653 --- /dev/null +++ b/skimage/_shared/tests/test_geometry.py @@ -0,0 +1,75 @@ +from skimage._shared._geometry import polygon_clip, polygon_area + +import numpy as np +from numpy.testing import assert_equal, assert_almost_equal + + +hand = np.array( + [[ 1.64516129, 1.16145833 ], + [ 1.64516129, 1.59375 ], + [ 1.35080645, 1.921875 ], + [ 1.375 , 2.18229167 ], + [ 1.68548387, 1.9375 ], + [ 1.60887097, 2.55208333 ], + [ 1.68548387, 2.69791667 ], + [ 1.76209677, 2.56770833 ], + [ 1.83064516, 1.97395833 ], + [ 1.89516129, 2.75 ], + [ 1.9516129 , 2.84895833 ], + [ 2.01209677, 2.76041667 ], + [ 1.99193548, 1.99479167 ], + [ 2.11290323, 2.63020833 ], + [ 2.2016129 , 2.734375 ], + [ 2.25403226, 2.60416667 ], + [ 2.14919355, 1.953125 ], + [ 2.30645161, 2.36979167 ], + [ 2.39112903, 2.36979167 ], + [ 2.41532258, 2.1875 ], + [ 2.1733871 , 1.703125 ], + [ 2.07782258, 1.16666667 ]]) + + +def test_polygon_area(): + x = [0, 0, 1, 1] + y = [0, 1, 1, 0] + + assert_almost_equal(polygon_area(y, x), 1) + + x = [0, 0, 1] + y = [0, 1, 1] + + assert_almost_equal(polygon_area(y, x), 0.5) + + x = [0, 0, 0.5, 1, 1, 0.5] + y = [0, 1, 0.5, 1, 0, 0.5] + + assert_almost_equal(polygon_area(y, x), 0.5) + + +def test_poly_clip(): + x = [0, 1, 2, 1] + y = [0, -1, 0, 1] + + yc, xc = polygon_clip(y, x, 0, 0, 1, 1) + assert_equal(polygon_area(yc, xc), 0.5) + + x = [-1, 1.5, 1.5, -1] + y = [.5, 0.5, 1.5, 1.5] + yc, xc = polygon_clip(y, x, 0, 0, 1, 1) + assert_equal(polygon_area(yc, xc), 0.5) + + +def test_hand_clip(): + (r0, c0, r1, c1) = (1.0, 1.5, 2.1, 2.5) + clip_r, clip_c = polygon_clip(hand[:, 1], hand[:, 0], r0, c0, r1, c1) + assert_equal(clip_r.size, 19) + assert_equal(clip_r[0], clip_r[-1]) + assert_equal(clip_c[0], clip_c[-1]) + + (r0, c0, r1, c1) = (1.0, 1.5, 1.7, 2.5) + clip_r, clip_c = polygon_clip(hand[:, 1], hand[:, 0], r0, c0, r1, c1) + assert_equal(clip_r.size, 6) + + (r0, c0, r1, c1) = (1.0, 1.5, 1.5, 2.5) + clip_r, clip_c = polygon_clip(hand[:, 1], hand[:, 0], r0, c0, r1, c1) + assert_equal(clip_r.size, 5) diff --git a/skimage/draw/__init__.py b/skimage/draw/__init__.py index 5f788ea7..01dfc5a7 100644 --- a/skimage/draw/__init__.py +++ b/skimage/draw/__init__.py @@ -1,4 +1,4 @@ -from .draw import circle, ellipse, set_color +from .draw import circle, ellipse, polygon_perimiter, set_color from .draw3d import ellipsoid, ellipsoid_stats from ._draw import (line, line_aa, polygon, ellipse_perimeter, circle_perimeter, circle_perimeter_aa, diff --git a/skimage/draw/draw.py b/skimage/draw/draw.py index 1624b115..f9ee214b 100644 --- a/skimage/draw/draw.py +++ b/skimage/draw/draw.py @@ -1,7 +1,11 @@ # coding: utf-8 import numpy as np + from ._draw import _coords_inside_image +from .._shared._geometry import polygon_clip +from ._draw import line + def _ellipse_in_shape(shape, center, radiuses): """Generate coordinates of points within ellipse bounded by shape.""" @@ -125,6 +129,83 @@ def circle(r, c, radius, shape=None): return ellipse(r, c, radius, radius, shape) +def polygon_perimiter(cy, cx, shape=None, clip=False): + """Generate polygon perimiter coordinates. + + Parameters + ---------- + y : (N,) ndarray + Y-coordinates of vertices of polygon. + x : (N,) ndarray + X-coordinates of vertices of polygon. + shape : tuple, optional + Image shape which is used to determine maximum extents of output pixel + coordinates. This is useful for polygons which exceed the image size. + By default the full extents of the polygon are used. + clip : bool, optional + Whether to clip the polygon to the provided shape. If this is set + to True, the drawn figure will always be a closed polygon with all + edges visible. + + Returns + ------- + rr, cc : ndarray of int + Pixel coordinates of polygon. + May be used to directly index into an array, e.g. + ``img[rr, cc] = 1``. + + Examples + -------- + >>> from skimage.draw import polygon_perimiter + >>> img = np.zeros((10, 10), dtype=np.uint8) + >>> rr, cc = polygon_perimiter([5, -1, 5, 10], + ... [-1, 5, 11, 5], + ... shape=img.shape, clip=True) + >>> img[rr, cc] = 1 + >>> img + array([[0, 0, 0, 0, 1, 1, 1, 0, 0, 0], + [0, 0, 0, 1, 0, 0, 0, 1, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0, 1, 0], + [0, 1, 0, 0, 0, 0, 0, 0, 0, 1], + [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], + [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], + [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], + [0, 1, 1, 0, 0, 0, 0, 0, 0, 1], + [0, 0, 0, 1, 0, 0, 0, 1, 1, 0], + [0, 0, 0, 0, 1, 1, 1, 0, 0, 0]], dtype=uint8) + + """ + if clip: + if shape is None: + raise ValueError("Must specify clipping shape") + clip_box = np.array([0, 0, shape[0] - 1, shape[1] - 1]) + else: + clip_box = np.array([np.min(cy), np.min(cx), + np.max(cy), np.max(cx)]) + + # Do the clipping irrespective of whether clip is set. This + # ensures that the returned polygon is closed and is an array. + cy, cx = polygon_clip(cy, cx, *clip_box) + + cy = np.round(cy).astype(int) + cx = np.round(cx).astype(int) + + # Construct line segments + rr, cc = [], [] + for i in range(len(cy) - 1): + line_r, line_c = line(cy[i], cx[i], cy[i + 1], cx[i + 1]) + rr.extend(line_r) + cc.extend(line_c) + + rr = np.asarray(rr) + cc = np.asarray(cc) + + if shape is None: + return rr, cc + else: + return _coords_inside_image(rr, cc, shape) + + def set_color(img, coords, color, alpha=1): """Set pixel color in the image at the given coordinates. diff --git a/skimage/draw/tests/test_draw.py b/skimage/draw/tests/test_draw.py index 214f09b0..c1cbe4b8 100644 --- a/skimage/draw/tests/test_draw.py +++ b/skimage/draw/tests/test_draw.py @@ -2,7 +2,7 @@ from numpy.testing import assert_array_equal, assert_equal, assert_raises import numpy as np from skimage._shared.testing import test_parallel -from skimage.draw import (set_color, line, line_aa, polygon, +from skimage.draw import (set_color, line, line_aa, polygon, polygon_perimiter, circle, circle_perimeter, circle_perimeter_aa, ellipse, ellipse_perimeter, _bezier_segment, bezier_curve) @@ -809,6 +809,37 @@ def test_bezier_curve_shape(): assert_array_equal(img, img_[shift:-shift, :]) +def test_polygon_perimiter(): + expected = np.array( + [[1, 1, 1, 1], + [1, 0, 0, 1], + [1, 1, 1, 1]] + ) + out = np.zeros_like(expected) + + rr, cc = polygon_perimiter([0, 2, 2, 0], + [0, 0, 3, 3]) + + out[rr, cc] = 1 + assert_array_equal(out, expected) + + out = np.zeros_like(expected) + rr, cc = polygon_perimiter([-1, -1, 3, 3], + [-1, 4, 4, -1], + shape=out.shape, clip=True) + out[rr, cc] = 1 + assert_array_equal(out, expected) + + assert_raises(ValueError, polygon_perimiter, [0], [1], clip=True) + + +def test_polygon_perimiter_outside_image(): + rr, cc = polygon_perimiter([-1, -1, 3, 3], + [-1, 4, 4, -1], shape=(3, 4)) + assert_equal(len(rr), 0) + assert_equal(len(cc), 0) + + if __name__ == "__main__": from numpy.testing import run_module_suite run_module_suite() From 4907da040929b3a3953974867dfe8a75f5873ded Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Mon, 29 Sep 2014 01:19:48 +0200 Subject: [PATCH 02/13] Update notes on algorithm. Switched from Liang-Barsky to Sutherland-Hodgman. --- skimage/_shared/_geometry.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/skimage/_shared/_geometry.py b/skimage/_shared/_geometry.py index 602692cb..27a03eef 100644 --- a/skimage/_shared/_geometry.py +++ b/skimage/_shared/_geometry.py @@ -21,14 +21,8 @@ def polygon_clip(rr, cc, r0, c0, r1, c1): Notes ----- - The algorithm is a translation of the Pascal code found in [1]_ and - includes fixes from Anti-Grain Geometry v2.4. - - References - ---------- - .. [1] You-Dong Liang and Brian A. Barsky, - An Analysis and Algorithm for Polygon Clipping, - Communications of the ACM, Vol 26, No 11, November 1983. + This makes use of Sutherland-Hodgman clipping as implemented in + AGG 2.4 and exposed in Matplotlib. """ from matplotlib import path, transforms From ad70668bc66f9d82c8a62b07dec184e5db335558 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Mon, 29 Sep 2014 01:21:24 +0200 Subject: [PATCH 03/13] Document output of polygon_area --- skimage/_shared/_geometry.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/skimage/_shared/_geometry.py b/skimage/_shared/_geometry.py index 27a03eef..6406b56d 100644 --- a/skimage/_shared/_geometry.py +++ b/skimage/_shared/_geometry.py @@ -42,6 +42,11 @@ def polygon_area(py, px): ---------- py, px : (N,) array of float Polygon coordinates. + + Returns + ------- + a : float + Area of the polygon. """ py = np.asarray(py) px = np.asarray(px) From 45f8bd2e72a6b4aa071f6d762bc263ce9dd3e4db Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Mon, 29 Sep 2014 02:17:48 +0200 Subject: [PATCH 04/13] Fix typos from PR feedback --- skimage/_shared/_geometry.py | 9 ++++----- skimage/draw/__init__.py | 2 +- skimage/draw/draw.py | 12 ++++++------ skimage/draw/tests/test_draw.py | 14 +++++++------- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/skimage/_shared/_geometry.py b/skimage/_shared/_geometry.py index 6406b56d..b31f86ed 100644 --- a/skimage/_shared/_geometry.py +++ b/skimage/_shared/_geometry.py @@ -3,16 +3,15 @@ __all__ = ['polygon_clip', 'polygon_area'] import numpy as np -def polygon_clip(rr, cc, r0, c0, r1, c1): +def polygon_clip(yp, xp, r0, c0, r1, c1): """Clip a polygon to the given bounding box. Parameters ---------- yp, xp : (N,) ndarray of double Row and column coordinates of the polygon. - ytop, xleft, ybottom, xright : double - Coordinates of the bounding box. Note that the following - must hold true: ``x_left < x_right`` and ``y_top < y_bottom``. + (r0, c0), (r1, c1) : double + Top-left and bottom-right coordinates of the bounding box. Returns ------- @@ -27,7 +26,7 @@ def polygon_clip(rr, cc, r0, c0, r1, c1): """ from matplotlib import path, transforms - poly = path.Path(np.vstack((rr, cc)).T, closed=True) + poly = path.Path(np.vstack((yp, xp)).T, closed=True) clip_rect = transforms.Bbox([[r0, c0], [r1, c1]]) poly_clipped = poly.clip_to_bbox(clip_rect).to_polygons()[0] diff --git a/skimage/draw/__init__.py b/skimage/draw/__init__.py index 01dfc5a7..81e86768 100644 --- a/skimage/draw/__init__.py +++ b/skimage/draw/__init__.py @@ -1,4 +1,4 @@ -from .draw import circle, ellipse, polygon_perimiter, set_color +from .draw import circle, ellipse, polygon_perimeter, set_color from .draw3d import ellipsoid, ellipsoid_stats from ._draw import (line, line_aa, polygon, ellipse_perimeter, circle_perimeter, circle_perimeter_aa, diff --git a/skimage/draw/draw.py b/skimage/draw/draw.py index f9ee214b..cd0b1d9b 100644 --- a/skimage/draw/draw.py +++ b/skimage/draw/draw.py @@ -129,14 +129,14 @@ def circle(r, c, radius, shape=None): return ellipse(r, c, radius, radius, shape) -def polygon_perimiter(cy, cx, shape=None, clip=False): - """Generate polygon perimiter coordinates. +def polygon_perimeter(cy, cx, shape=None, clip=False): + """Generate polygon perimeter coordinates. Parameters ---------- - y : (N,) ndarray + cy : (N,) ndarray Y-coordinates of vertices of polygon. - x : (N,) ndarray + cx : (N,) ndarray X-coordinates of vertices of polygon. shape : tuple, optional Image shape which is used to determine maximum extents of output pixel @@ -156,9 +156,9 @@ def polygon_perimiter(cy, cx, shape=None, clip=False): Examples -------- - >>> from skimage.draw import polygon_perimiter + >>> from skimage.draw import polygon_perimeter >>> img = np.zeros((10, 10), dtype=np.uint8) - >>> rr, cc = polygon_perimiter([5, -1, 5, 10], + >>> rr, cc = polygon_perimeter([5, -1, 5, 10], ... [-1, 5, 11, 5], ... shape=img.shape, clip=True) >>> img[rr, cc] = 1 diff --git a/skimage/draw/tests/test_draw.py b/skimage/draw/tests/test_draw.py index c1cbe4b8..d1ab8612 100644 --- a/skimage/draw/tests/test_draw.py +++ b/skimage/draw/tests/test_draw.py @@ -2,7 +2,7 @@ from numpy.testing import assert_array_equal, assert_equal, assert_raises import numpy as np from skimage._shared.testing import test_parallel -from skimage.draw import (set_color, line, line_aa, polygon, polygon_perimiter, +from skimage.draw import (set_color, line, line_aa, polygon, polygon_perimeter, circle, circle_perimeter, circle_perimeter_aa, ellipse, ellipse_perimeter, _bezier_segment, bezier_curve) @@ -809,7 +809,7 @@ def test_bezier_curve_shape(): assert_array_equal(img, img_[shift:-shift, :]) -def test_polygon_perimiter(): +def test_polygon_perimeter(): expected = np.array( [[1, 1, 1, 1], [1, 0, 0, 1], @@ -817,24 +817,24 @@ def test_polygon_perimiter(): ) out = np.zeros_like(expected) - rr, cc = polygon_perimiter([0, 2, 2, 0], + rr, cc = polygon_perimeter([0, 2, 2, 0], [0, 0, 3, 3]) out[rr, cc] = 1 assert_array_equal(out, expected) out = np.zeros_like(expected) - rr, cc = polygon_perimiter([-1, -1, 3, 3], + rr, cc = polygon_perimeter([-1, -1, 3, 3], [-1, 4, 4, -1], shape=out.shape, clip=True) out[rr, cc] = 1 assert_array_equal(out, expected) - assert_raises(ValueError, polygon_perimiter, [0], [1], clip=True) + assert_raises(ValueError, polygon_perimeter, [0], [1], clip=True) -def test_polygon_perimiter_outside_image(): - rr, cc = polygon_perimiter([-1, -1, 3, 3], +def test_polygon_perimeter_outside_image(): + rr, cc = polygon_perimeter([-1, -1, 3, 3], [-1, 4, 4, -1], shape=(3, 4)) assert_equal(len(rr), 0) assert_equal(len(cc), 0) From 5280cacb829273790e6199624aefda91be2849b6 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Mon, 29 Sep 2014 23:10:35 +0200 Subject: [PATCH 05/13] Avoid matplotlib testing problems on Travis-CI --- skimage/draw/draw.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/skimage/draw/draw.py b/skimage/draw/draw.py index cd0b1d9b..03b554c7 100644 --- a/skimage/draw/draw.py +++ b/skimage/draw/draw.py @@ -6,6 +6,11 @@ from ._draw import _coords_inside_image from .._shared._geometry import polygon_clip from ._draw import line +from skimage._shared.version_requirements import is_installed +matplotlib_installed = is_installed('matplotlib') +if not matplotlib_installed: + warn('Polygon perimeter drawing requires matplotlib') + def _ellipse_in_shape(shape, center, radiuses): """Generate coordinates of points within ellipse bounded by shape.""" From 5e906fb4eceb0631e46da1856bc73c1e05f26c99 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Tue, 30 Sep 2014 00:14:48 +0200 Subject: [PATCH 06/13] Add missing import --- skimage/draw/draw.py | 1 + 1 file changed, 1 insertion(+) diff --git a/skimage/draw/draw.py b/skimage/draw/draw.py index 03b554c7..85b076af 100644 --- a/skimage/draw/draw.py +++ b/skimage/draw/draw.py @@ -7,6 +7,7 @@ from .._shared._geometry import polygon_clip from ._draw import line from skimage._shared.version_requirements import is_installed +from warnings import warn matplotlib_installed = is_installed('matplotlib') if not matplotlib_installed: warn('Polygon perimeter drawing requires matplotlib') From 96e9e773882440468d41a3ef1823f98849b78f10 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Tue, 4 Nov 2014 17:52:36 +0200 Subject: [PATCH 07/13] PEP8 cleanups --- skimage/draw/tests/test_draw.py | 330 ++++++++++++++++---------------- 1 file changed, 165 insertions(+), 165 deletions(-) diff --git a/skimage/draw/tests/test_draw.py b/skimage/draw/tests/test_draw.py index d1ab8612..a4a421ba 100644 --- a/skimage/draw/tests/test_draw.py +++ b/skimage/draw/tests/test_draw.py @@ -213,21 +213,21 @@ def test_circle(): img[rr, cc] = 1 img_ = np.array( - [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0], - [0, 0, 0, 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, 1, 1, 1, 1, 1, 1, 0, 0], + [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0], + [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] ) assert_array_equal(img, img_) @@ -336,7 +336,7 @@ def test_circle_perimeter_aa(): [ 0, 0, 0, 0, 189, 172, 74, 18, 0, 18, 74, 172, 189, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 82, 180, 236, 255, 236, 180, 82, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] - ) + ) assert_array_equal(img, img_) @@ -490,21 +490,21 @@ def test_ellipse_with_shape(): img[rr, cc] = 1 img_ = np.array( - [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], - [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], - [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], - [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], - [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] + [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] ) assert_array_equal(img, img_) @@ -559,36 +559,36 @@ def test_ellipse_perimeter_zeroangle(): rr, cc = ellipse_perimeter(15, 7, 14, 6, 0) img[rr, cc] = 1 img_ = np.array( - [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 1, 1, 1, 0,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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0]] ) assert_array_equal(img, img_) @@ -600,36 +600,36 @@ def test_ellipse_perimeter_nzeroangle(): rr, cc = ellipse_perimeter(15, 11, 12, 6, 1.1) img[rr, cc] = 1 img_ = np.array( - [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] ) assert_array_equal(img, img_) @@ -670,32 +670,32 @@ def test_bezier_segment_curved(): rr, cc = _bezier_segment(x1, y1, x2, y2, x3, y3, 1) img[rr, cc] = 1 img_ = np.array( - [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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q_1(): assert_equal(img[x1, y1], 1) assert_equal(img[x3, y3], 1) img_ = np.array( - [[0, 0, 0, 0, 0, 0, 0, 0], - [0, 1, 0, 0, 0, 0, 0, 0], - [0, 0, 1, 0, 0, 0, 0, 0], - [0, 0, 0, 1, 0, 0, 0, 0], - [0, 0, 0, 0, 1, 0, 0, 0], - [0, 0, 0, 0, 1, 0, 0, 0], - [0, 0, 0, 0, 0, 1, 0, 0], - [0, 0, 0, 0, 0, 1, 0, 0], - [0, 0, 0, 0, 0, 0, 1, 0], - [0, 0, 0, 0, 0, 0, 1, 0], - [0, 0, 0, 0, 0, 0, 1, 0], - [0, 0, 0, 0, 0, 0, 1, 0], - [0, 0, 0, 0, 0, 0, 1, 0], - [0, 0, 0, 0, 0, 0, 1, 0], - [0, 0, 0, 0, 0, 0, 1, 0], - [0, 0, 0, 0, 0, 1, 0, 0], - [0, 0, 0, 0, 0, 1, 0, 0], - [0, 0, 0, 0, 1, 0, 0, 0], - [0, 0, 0, 0, 1, 0, 0, 0], - [0, 0, 0, 1, 0, 0, 0, 0], - [0, 0, 1, 0, 0, 0, 0, 0], - [0, 1, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0]] - ) + [[0, 0, 0, 0, 0, 0, 0, 0], + [0, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 1, 0, 0, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 0], + [0, 0, 0, 0, 0, 0, 1, 0], + [0, 0, 0, 0, 0, 0, 1, 0], + [0, 0, 0, 0, 0, 0, 1, 0], + [0, 0, 0, 0, 0, 0, 1, 0], + [0, 0, 0, 0, 0, 0, 1, 0], + [0, 0, 0, 0, 0, 0, 1, 0], + [0, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 1, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0], + [0, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0]] + ) assert_equal(img, img_) @@ -765,30 +765,30 @@ def test_bezier_curved_weight_neq_1(): assert_equal(img[x1, y1], 1) assert_equal(img[x3, y3], 1) img_ = np.array( - [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 1, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 1, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 1, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 1, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 1, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], - [0, 0, 0, 0, 0, 0, 0, 1, 0, 0], - [0, 0, 0, 0, 0, 0, 1, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 1, 0, 0, 0], - [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], - [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], - [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], - [0, 0, 1, 0, 0, 0, 0, 0, 0, 0], - [0, 1, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] - ) + [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 0, 0, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0], + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] + ) assert_equal(img, img_) @@ -814,7 +814,7 @@ def test_polygon_perimeter(): [[1, 1, 1, 1], [1, 0, 0, 1], [1, 1, 1, 1]] - ) + ) out = np.zeros_like(expected) rr, cc = polygon_perimeter([0, 2, 2, 0], From 32182574eca9c20ad918f74be0afc9aeb8d21a4e Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Mon, 10 Nov 2014 11:53:13 +0200 Subject: [PATCH 08/13] Update coordinate convention, inline matplotlib `clip_to_bbox` The `clip_to_bbox` function is only available in later versions of Matplotlib, so for now inline it so that we remain compatible with v1.1. --- TODO.txt | 3 ++- skimage/_shared/_geometry.py | 31 +++++++++++++++++++------------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/TODO.txt b/TODO.txt index 67429880..b483cc31 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,9 +1,10 @@ Remember to list any API changes below in `doc/source/api_changes.txt`. - Version 0.14 ------------ +* In `skimage._shared._geometry`, remove `clip_to_bbox` and replace with + `poly.clip_to_bbox`, if our dependency on Matplotlib is now >= 1.2. * Remove deprecated ``ntiles_*` kwargs in ``equalize_adapthist``. * Remove deprecated ``skimage.restoration.nl_means_denoising``. * Remove deprecated ``skimage.filters.gaussian_filter``. diff --git a/skimage/_shared/_geometry.py b/skimage/_shared/_geometry.py index b31f86ed..08d0e567 100644 --- a/skimage/_shared/_geometry.py +++ b/skimage/_shared/_geometry.py @@ -3,19 +3,19 @@ __all__ = ['polygon_clip', 'polygon_area'] import numpy as np -def polygon_clip(yp, xp, r0, c0, r1, c1): +def polygon_clip(rp, cp, r0, c0, r1, c1): """Clip a polygon to the given bounding box. Parameters ---------- - yp, xp : (N,) ndarray of double + rp, cp : (N,) ndarray of double Row and column coordinates of the polygon. (r0, c0), (r1, c1) : double Top-left and bottom-right coordinates of the bounding box. Returns ------- - y_clipped, x_clipped : (M,) ndarray of double + r_clipped, c_clipped : (M,) ndarray of double Coordinates of clipped polygon. Notes @@ -24,29 +24,36 @@ def polygon_clip(yp, xp, r0, c0, r1, c1): AGG 2.4 and exposed in Matplotlib. """ - from matplotlib import path, transforms + from matplotlib import _path, path, transforms - poly = path.Path(np.vstack((yp, xp)).T, closed=True) + # `clip_to_bbox` is included directly from Matplotlib + # since it was only included after v1.1 + def clip_to_bbox(poly_path, bbox, inside=True): + verts = _path.clip_path_to_rect(poly_path, bbox, inside) + paths = [path.Path(poly) for poly in verts] + return poly_path.make_compound_path(*paths) + + poly = path.Path(np.vstack((rp, cp)).T, closed=True) clip_rect = transforms.Bbox([[r0, c0], [r1, c1]]) - poly_clipped = poly.clip_to_bbox(clip_rect).to_polygons()[0] + poly_clipped = clip_to_bbox(poly, clip_rect).to_polygons()[0] return poly_clipped[:, 0], poly_clipped[:, 1] -def polygon_area(py, px): +def polygon_area(pr, pc): """Compute the area of a polygon. Parameters ---------- - py, px : (N,) array of float - Polygon coordinates. + pr, pc : (N,) array of float + Polygon row and column coordinates. Returns ------- a : float Area of the polygon. """ - py = np.asarray(py) - px = np.asarray(px) - return 0.5 * np.abs(np.sum((px[:-1] * py[1:]) - (px[1:] * py[:-1]))) + pr = np.asarray(pr) + pc = np.asarray(pc) + return 0.5 * np.abs(np.sum((pc[:-1] * pr[1:]) - (pc[1:] * pr[:-1]))) From bf7e885064e545496a55ccbbdc9f56eebb7ac0a4 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Mon, 10 Nov 2014 12:35:04 +0200 Subject: [PATCH 09/13] Polygon clipping requires mpl, but it is now a dependency. Remove warning. --- skimage/draw/draw.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/skimage/draw/draw.py b/skimage/draw/draw.py index 85b076af..cd0b1d9b 100644 --- a/skimage/draw/draw.py +++ b/skimage/draw/draw.py @@ -6,12 +6,6 @@ from ._draw import _coords_inside_image from .._shared._geometry import polygon_clip from ._draw import line -from skimage._shared.version_requirements import is_installed -from warnings import warn -matplotlib_installed = is_installed('matplotlib') -if not matplotlib_installed: - warn('Polygon perimeter drawing requires matplotlib') - def _ellipse_in_shape(shape, center, radiuses): """Generate coordinates of points within ellipse bounded by shape.""" From be667e094740b3784a33db0712839cdc577cf235 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Mon, 14 Dec 2015 01:05:55 -0800 Subject: [PATCH 10/13] Work around end-point duplication bug in Matplotlib --- skimage/_shared/_geometry.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/skimage/_shared/_geometry.py b/skimage/_shared/_geometry.py index 08d0e567..b49fef5d 100644 --- a/skimage/_shared/_geometry.py +++ b/skimage/_shared/_geometry.py @@ -35,9 +35,11 @@ def polygon_clip(rp, cp, r0, c0, r1, c1): poly = path.Path(np.vstack((rp, cp)).T, closed=True) clip_rect = transforms.Bbox([[r0, c0], [r1, c1]]) - poly_clipped = clip_to_bbox(poly, clip_rect).to_polygons()[0] + if np.all(poly_clipped[-1] == poly_clipped[-2]): + poly_clipped = poly_clipped[:-1] + return poly_clipped[:, 0], poly_clipped[:, 1] From 41569beacb15018de50e4738b2d02fc166dc3eca Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Tue, 2 Feb 2016 08:23:51 -0800 Subject: [PATCH 11/13] With matplotlib dependency raised to 1.3, remove inlined clipping code --- TODO.txt | 3 +-- requirements.txt | 2 +- skimage/_shared/_geometry.py | 13 +++---------- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/TODO.txt b/TODO.txt index b483cc31..67429880 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,10 +1,9 @@ Remember to list any API changes below in `doc/source/api_changes.txt`. + Version 0.14 ------------ -* In `skimage._shared._geometry`, remove `clip_to_bbox` and replace with - `poly.clip_to_bbox`, if our dependency on Matplotlib is now >= 1.2. * Remove deprecated ``ntiles_*` kwargs in ``equalize_adapthist``. * Remove deprecated ``skimage.restoration.nl_means_denoising``. * Remove deprecated ``skimage.filters.gaussian_filter``. diff --git a/requirements.txt b/requirements.txt index 98c1b49a..7abedb00 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -matplotlib>=1.1.0 +matplotlib>=1.3.1 numpy>=1.7.2 scipy>=0.9.0 six>=1.4 diff --git a/skimage/_shared/_geometry.py b/skimage/_shared/_geometry.py index b49fef5d..1ae30eec 100644 --- a/skimage/_shared/_geometry.py +++ b/skimage/_shared/_geometry.py @@ -1,6 +1,7 @@ __all__ = ['polygon_clip', 'polygon_area'] import numpy as np +from matplotlib import _path, path, transforms def polygon_clip(rp, cp, r0, c0, r1, c1): @@ -24,19 +25,11 @@ def polygon_clip(rp, cp, r0, c0, r1, c1): AGG 2.4 and exposed in Matplotlib. """ - from matplotlib import _path, path, transforms - - # `clip_to_bbox` is included directly from Matplotlib - # since it was only included after v1.1 - def clip_to_bbox(poly_path, bbox, inside=True): - verts = _path.clip_path_to_rect(poly_path, bbox, inside) - paths = [path.Path(poly) for poly in verts] - return poly_path.make_compound_path(*paths) - poly = path.Path(np.vstack((rp, cp)).T, closed=True) clip_rect = transforms.Bbox([[r0, c0], [r1, c1]]) - poly_clipped = clip_to_bbox(poly, clip_rect).to_polygons()[0] + poly_clipped = poly.clip_to_bbox(clip_rect).to_polygons()[0] + # This should be fixed in matplotlib >1.5 if np.all(poly_clipped[-1] == poly_clipped[-2]): poly_clipped = poly_clipped[:-1] From a39dac7c52deae3c456d384ab809de73c8f32f94 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Tue, 2 Feb 2016 08:31:59 -0800 Subject: [PATCH 12/13] Use row/column instead of x, y convention --- skimage/draw/draw.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/skimage/draw/draw.py b/skimage/draw/draw.py index cd0b1d9b..340292ea 100644 --- a/skimage/draw/draw.py +++ b/skimage/draw/draw.py @@ -129,15 +129,15 @@ def circle(r, c, radius, shape=None): return ellipse(r, c, radius, radius, shape) -def polygon_perimeter(cy, cx, shape=None, clip=False): +def polygon_perimeter(cr, cc, shape=None, clip=False): """Generate polygon perimeter coordinates. Parameters ---------- - cy : (N,) ndarray - Y-coordinates of vertices of polygon. - cx : (N,) ndarray - X-coordinates of vertices of polygon. + cr : (N,) ndarray + Row (Y) coordinates of vertices of polygon. + cc : (N,) ndarray + Column (X) coordinates of vertices of polygon. shape : tuple, optional Image shape which is used to determine maximum extents of output pixel coordinates. This is useful for polygons which exceed the image size. @@ -149,10 +149,10 @@ def polygon_perimeter(cy, cx, shape=None, clip=False): Returns ------- - rr, cc : ndarray of int + pr, pc : ndarray of int Pixel coordinates of polygon. May be used to directly index into an array, e.g. - ``img[rr, cc] = 1``. + ``img[pr, pc] = 1``. Examples -------- @@ -180,30 +180,30 @@ def polygon_perimeter(cy, cx, shape=None, clip=False): raise ValueError("Must specify clipping shape") clip_box = np.array([0, 0, shape[0] - 1, shape[1] - 1]) else: - clip_box = np.array([np.min(cy), np.min(cx), - np.max(cy), np.max(cx)]) + clip_box = np.array([np.min(cr), np.min(cc), + np.max(cr), np.max(cc)]) # Do the clipping irrespective of whether clip is set. This # ensures that the returned polygon is closed and is an array. - cy, cx = polygon_clip(cy, cx, *clip_box) + cr, cc = polygon_clip(cr, cc, *clip_box) - cy = np.round(cy).astype(int) - cx = np.round(cx).astype(int) + cr = np.round(cr).astype(int) + cc = np.round(cc).astype(int) # Construct line segments - rr, cc = [], [] - for i in range(len(cy) - 1): - line_r, line_c = line(cy[i], cx[i], cy[i + 1], cx[i + 1]) - rr.extend(line_r) - cc.extend(line_c) + pr, pc = [], [] + for i in range(len(cr) - 1): + line_r, line_c = line(cr[i], cc[i], cr[i + 1], cc[i + 1]) + pr.extend(line_r) + pc.extend(line_c) - rr = np.asarray(rr) - cc = np.asarray(cc) + pr = np.asarray(pr) + pc = np.asarray(pc) if shape is None: - return rr, cc + return pr, pc else: - return _coords_inside_image(rr, cc, shape) + return _coords_inside_image(pr, pc, shape) def set_color(img, coords, color, alpha=1): From aa31c3d24e7b10c91697659c47761e97ba06648c Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Tue, 2 Feb 2016 12:39:01 -0800 Subject: [PATCH 13/13] Up minimal six dependency to work with minimal Matplotlib --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7abedb00..1e6921be 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ matplotlib>=1.3.1 numpy>=1.7.2 scipy>=0.9.0 -six>=1.4 +six>=1.7.3 networkx>=1.8 pillow>=2.1.0 dask[array]>=0.5.0