refine.py 文件源码

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

项目:circletracking 作者: caspervdw 项目源码 文件源码
def unwrap_ellipse(image, params, rad_range, num_points=None, spline_order=3):
    """ Unwraps an circular or ellipse-shaped feature into elliptic coordinates.

    Transforms an image in (y, x) space to (theta, r) space, using elliptic
    coordinates. The theta coordinate is tangential to the ellipse, the r
    coordinate is normal to the ellipse. r=0 at the ellipse: inside the ellipse,
    r < 0.

    Parameters
    ----------
    image : ndarray, 2d
    params : (yr, xr, yc, xc)
    rad_range : tuple
        A tuple defining the range of r to interpolate.
    num_points : number, optional
        The number of ``theta`` values. By default, this equals the
        ellipse circumference: approx. every pixel there is an interpolation.
    spline_order : number, optional
        The order of the spline interpolation. Default 3.

    Returns
    -------
    intensity : the interpolated image in (theta, r) space
    pos : the (y, x) positions of the ellipse grid
    normal : the (y, x) unit vectors normal to the ellipse grid
    """
    yr, xr, yc, xc = params
    # compute the r coordinates
    steps = np.arange(rad_range[0], rad_range[1] + 1, 1)
    # compute the (y, x) positions and unit normals of the ellipse
    pos, normal = ellipse_grid((yr, xr), (yc, xc), n=num_points, spacing=1)
    # calculate all the (y, x) coordinates on which the image interpolated.
    # this is a 3D array of shape [n_theta, n_r, 2], with 2 being y and x.
    coords = normal[:, :, np.newaxis] * steps[np.newaxis, np.newaxis, :] + \
        pos[:, :, np.newaxis]
    # interpolate the image on computed coordinates
    intensity = map_coordinates(image, coords, order=spline_order,
                                output=np.float)
    return intensity, pos, normal
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号