0

我正在阅读谷歌的一些投影几何图像变形代码

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 开始的“半整数坐标”的原因是什么?

4

1 回答 1

1

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

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

简而言之,它只是坐标系的选择。你使用什么坐标系并不重要,只要你始终如一地使用它。

于 2021-12-08T17:01:34.407 回答