我正在阅读谷歌的一些投影几何图像变形代码
def WarpCoordinatesWithHomography(homography, rect, cfg):
"""Computes the warped coordinates from rect through homography.
Computes the corresponding coordinates on the image for each pixel of rect.
Note that the returned coordinates are in x, y order.
The returned image can be used to warp from the image to the
pixels of the depth_plane within rect.
warp_coordinates = ApplyHomographyToCoords(....)
warped_from_image(x, y) = image(warp_coordinates(x, y)[0],
warp_coordinates(x, y)[1])
Args:
homography: A 3x3 tensor representing the transform applied to the
coordinates inside rect.
rect: An integer tensor [start_y, start_x, end_y, end_x] representing a rect.
Returns:
Returns a rect.height * rect.width * 2 tensor filled with image
coordinates.
"""
ys = tf.cast(tf.range(rect[0], rect[2]), cfg.vx_tf_dtype)
xs = tf.cast(tf.range(rect[1], rect[3]), cfg.vx_tf_dtype)
# Adds 0.5, as pixel centers are assumed to be at half integer coordinates.
image_coords_t = tf.stack(tf.meshgrid(xs, ys), axis=-1) + 0.5
hom_image_coords_t = tf.concat(
(image_coords_t, tf.ones([rect[2] - rect[0], rect[3] - rect[1], 1])),
axis=-1)
hom_warped_coords = tf.einsum('ijk,lk->ijl', hom_image_coords_t, homography)
res = tf.math.divide_no_nan(hom_warped_coords[:, :, :-1], hom_warped_coords[:, :, 2:3])
return res
使用从 0.5 开始的“半整数坐标”的原因是什么?