mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-11 23:08:50 +08:00
minor fixes
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
-------
|
||||
|
||||
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user