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
评论列表
文章目录