半整数坐标的原因



我正在阅读谷歌中的一些投影几何图像扭曲代码

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开始?

有些人认为像素是网格中的点样本,有些人认为它们是1x1正方形。

在后一类中,一些人认为1x1正方形以整数坐标为中心,例如,一个正方形的范围从0.5到1.5。例如,其他人认为正方形在0.0到1.0的范围内,因此像素以"0"为中心;半整数";。

简而言之,它只是一个坐标系的选择。使用哪种坐标系并不重要,只要始终使用即可。

相关内容

  • 没有找到相关文章

最新更新