From 328e54fa13d6c2d7ae7539b87982872a13d48fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Boulogne?= Date: Sun, 21 Apr 2013 15:31:57 +0200 Subject: [PATCH] minor fixes --- doc/examples/plot_shapes.py | 20 +++++++++++++++++--- skimage/draw/_draw.pyx | 14 ++++++++------ skimage/draw/tests/test_draw.py | 3 ++- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/doc/examples/plot_shapes.py b/doc/examples/plot_shapes.py index 8142c2d0..fcb72863 100644 --- a/doc/examples/plot_shapes.py +++ b/doc/examples/plot_shapes.py @@ -14,8 +14,10 @@ This example shows how to fill several different shapes: import numpy as np import matplotlib.pyplot as plt -from skimage.draw import line, polygon, circle, circle_perimeter, ellipse - +from skimage.draw import line, polygon, circle, circle_perimeter, \ + ellipse, ellipse_perimeter, bezier_curve +import numpy as np +import math img = np.zeros((500, 500, 3), 'uint8') @@ -43,8 +45,20 @@ rr, cc = ellipse(300, 300, 100, 200, img.shape) img[rr,cc,2] = 255 # circle -rr, cc = circle_perimeter(120, 400, 50) +rr, cc = circle_perimeter(120, 400, 15) +img[rr, cc, :] = (255, 0, 0) + +# ellipses +rr, cc = ellipse_perimeter(120, 400, 60, 20, orientation=math.pi/4.) img[rr, cc, :] = (255, 0, 255) +rr, cc = ellipse_perimeter(120, 400, 60, 20, orientation=-math.pi/4.) +img[rr, cc, :] = (0, 0, 255) +rr, cc = ellipse_perimeter(120, 400, 60, 20, orientation=math.pi/2.) +img[rr, cc, :] = (255, 255, 255) + +# bezier curve +rr, cc = bezier_curve(120, 400, 150, 480, 160, 400, weight=2) +img[rr, cc, :] = (255, 255, 255) plt.imshow(img) plt.show() diff --git a/skimage/draw/_draw.pyx b/skimage/draw/_draw.pyx index be1e6199..0356e8f9 100644 --- a/skimage/draw/_draw.pyx +++ b/skimage/draw/_draw.pyx @@ -265,7 +265,7 @@ def circle_perimeter(Py_ssize_t cy, Py_ssize_t cx, Py_ssize_t radius, def ellipse_perimeter(Py_ssize_t cy, Py_ssize_t cx, Py_ssize_t yradius, - Py_ssize_t xradius, double angle=0): + Py_ssize_t xradius, double orientation=0): """Generate ellipse perimeter coordinates. Parameters @@ -274,8 +274,8 @@ def ellipse_perimeter(Py_ssize_t cy, Py_ssize_t cx, Py_ssize_t yradius, Centre coordinate of ellipse. yradius, xradius: int Minor and major semi-axes. ``(x/xradius)**2 + (y/yradius)**2 = 1``. - angle: double, optional - Major axis angle (in radian). + orientation: double, optional + Major axis orientation in clockwise direction as radians. Returns ------- @@ -326,7 +326,7 @@ def ellipse_perimeter(Py_ssize_t cy, Py_ssize_t cx, Py_ssize_t yradius, cdef int ix0, ix1, iy0, iy1, ixd, iyd cdef double sin_angle, xa, ya, za, a, b - if angle == 0: + if orientation == 0: x = -xradius y = 0 e2 = yd @@ -360,7 +360,7 @@ def ellipse_perimeter(Py_ssize_t cy, Py_ssize_t cx, Py_ssize_t yradius, py.append(cy - y) else: - sin_angle = sin(angle) + sin_angle = sin(orientation) za = (xd - yd) * sin_angle xa = sqrt(xd - za * sin_angle) ya = sqrt(yd + za * sin_angle) @@ -376,7 +376,7 @@ def ellipse_perimeter(Py_ssize_t cy, Py_ssize_t cx, Py_ssize_t yradius, xa = ix1 - ix0 ya = iy1 - iy0 - za = 4 * za * cos(angle) + za = 4 * za * cos(orientation) w = xa * ya if w != 0: w = (w - za) / (w + w) @@ -414,6 +414,8 @@ def bezier_curve(Py_ssize_t x0, Py_ssize_t y0, Coordinates of the middle point x2, y2 : int Coordinates of the last point + weight : double + Middle point weight, it describes the line tension. Returns ------- diff --git a/skimage/draw/tests/test_draw.py b/skimage/draw/tests/test_draw.py index ff494ad2..ce2e17ba 100644 --- a/skimage/draw/tests/test_draw.py +++ b/skimage/draw/tests/test_draw.py @@ -1,7 +1,8 @@ from numpy.testing import assert_array_equal import numpy as np -from skimage.draw import line, polygon, circle, circle_perimeter, ellipse, ellipse_perimeter, bezier_curve +from skimage.draw import line, polygon, circle, circle_perimeter, \ + ellipse, ellipse_perimeter, bezier_curve def test_line_horizontal():