draw.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:fg21sim 作者: liweitianux 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号