interpolation.py 文件源码

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

项目:mrflow 作者: jswulff 项目源码 文件源码
def interp_lin(I, xn, yn, compute_derivs=True):
    """ Perform linear interpolation of I.

    I is evaluated at xn, yn.

    Returns
    -------
    I_warped : array_like
        Warped image
    dI_warped_dx : array_like
        Derivative of warped image in x direction
    dI_warped_dy : array_like
        Derivative of warped image in y direction
    """

    I_warped = cv2.remap(I.astype('float32'),
                         xn.astype('float32'),
                         yn.astype('float32'),
                         borderMode=cv2.BORDER_REPLICATE,
                         interpolation=cv2.INTER_CUBIC)

    if compute_derivs:
        if True:
            dI_dy, dI_dx = np.gradient(I)[:2]
            dI_warped_dy = cv2.remap(dI_dy.astype('float32'),
                                xn.astype('float32'),
                                yn.astype('float32'),
                                borderMode=cv2.BORDER_REPLICATE,
                                interpolation=cv2.INTER_CUBIC)

            dI_warped_dx = cv2.remap(dI_dx.astype('float32'),
                                xn.astype('float32'),
                                yn.astype('float32'),
                                borderMode=cv2.BORDER_REPLICATE,
                                interpolation=cv2.INTER_CUBIC)
        else:
            dI_warped_dy, dI_warped_dx = np.gradient(I_warped)[:2]

        return I_warped, dI_warped_dx, dI_warped_dy

    # If we don't want to compute the derivatives
    return I_warped
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号