半整数坐标的原因

The reason for the half integer coordinates

我正在阅读来自 Google

的一些射影几何图像变形代码
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,因此像素以“半整数”为中心。

简单来说就是坐标系的选择。使用什么坐标系并不重要,只要您始终如一地使用它。