transform.py 文件源码

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

项目:fg21sim 作者: liweitianux 项目源码 文件源码
def circle2ellipse(imgcirc, bfraction, rotation=None):
    """
    Shrink the input circle image with respect to the center along the
    column (axis) to transform the circle to an ellipse, and then rotate
    around the image center.

    Parameters
    ----------
    imgcirc : 2D `~numpy.ndarray`
        Input image grid containing a circle at the center
    bfraction : float
        The fraction of the semi-minor axis w.r.t. the semi-major axis
        (i.e., the half width of the input image), to determine the
        shrunk size (height) of the output image.
        Should be a fraction within [0, 1]
    rotation : float, optional
        Rotation angle (unit: [deg])
        Default: ``None`` (i.e., no rotation)

    Returns
    -------
    imgout : 2D `~numpy.ndarray`
        Image of the same size as the input circle image.
    """
    nrow, ncol = imgcirc.shape
    # Shrink the circle to be elliptical
    nrow2 = nrow * bfraction
    nrow2 = int(nrow2 / 2) * 2 + 1  # be odd
    # NOTE: zoom() calculate the output shape with round() instead of int();
    #       fix the warning about they may be different.
    zoom = ((nrow2+0.1)/nrow, 1)
    img2 = ndimage.zoom(imgcirc, zoom=zoom, order=1)
    # Pad the shrunk image to have the same size as input
    imgout = np.zeros(shape=(nrow, ncol))
    r1 = int((nrow - nrow2) / 2)
    imgout[r1:(r1+nrow2), :] = img2
    if rotation:
        imgout = ndimage.rotate(imgout, angle=rotation, reshape=False, order=1)
    return imgout
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号