def _ellipse_in_shape(shape, center, radii, rotation=0.0):
"""
Generate coordinates of points within ellipse bounded by shape.
Parameters
----------
shape : int tuple (nrow, ncol)
Shape of the input image. Must be length 2.
center : iterable of floats
(row, column) position of center inside the given shape.
radii : iterable of floats
Size of two half axes (for row and column)
rotation : float, optional
Rotation of the ellipse defined by the above, in counter-clockwise
direction, with respect to the column-axis.
Unit: [deg]
Returns
-------
rows : iterable of ints
Row coordinates representing values within the ellipse.
cols : iterable of ints
Corresponding column coordinates representing values within
the ellipse.
Credit
------
* scikit-image - skimage/draw/draw.py
"""
rotation = np.deg2rad(rotation)
r_lim, c_lim = np.ogrid[0:float(shape[0]), 0:float(shape[1])]
r_org, c_org = center
r_rad, c_rad = radii
rotation %= np.pi
sin_alpha, cos_alpha = np.sin(rotation), np.cos(rotation)
r, c = (r_lim - r_org), (c_lim - c_org)
distances = (((r * cos_alpha + c * sin_alpha) / r_rad) ** 2 +
((r * sin_alpha - c * cos_alpha) / c_rad) ** 2)
return np.nonzero(distances < 1)
评论列表
文章目录