MCPcopy Index your code
hub / github.com/apple/ml-pointersect / find_corresponding_uv

Function find_corresponding_uv

plib/utils.py:1242–1310  ·  view source on GitHub ↗

Compute the correspoding points in image coordinates of the pixels in a source image. Args: uv_c: (*b_shape, *n_shape, 2) the source pixels, on image grid, integer, within image boundary u is along the column axis, v is along the row axis. [0, w], [0, h]

(
        uv_c: torch.Tensor,
        z_map: torch.Tensor,
        intrinsics_from: torch.Tensor,
        H_c2w_from: torch.Tensor,
        intrinsics_to: torch.Tensor,
        H_c2w_to: torch.Tensor,
        dim_b: int = 0,
)

Source from the content-addressed store, hash-verified

1240
1241
1242def find_corresponding_uv(
1243 uv_c: torch.Tensor,
1244 z_map: torch.Tensor,
1245 intrinsics_from: torch.Tensor,
1246 H_c2w_from: torch.Tensor,
1247 intrinsics_to: torch.Tensor,
1248 H_c2w_to: torch.Tensor,
1249 dim_b: int = 0,
1250) -> torch.Tensor:
1251 """
1252 Compute the correspoding points in image coordinates of the pixels in a source image.
1253
1254 Args:
1255 uv_c:
1256 (*b_shape, *n_shape, 2) the source pixels, on image grid, integer, within image boundary
1257 u is along the column axis, v is along the row axis. [0, w], [0, h]
1258 Note that the pixel center is at [x.5, y.5].
1259 z_map:
1260 (*b_shape, h, w) the z coordinate of the point in the source camera coordinate on the sensor,
1261 not along the corresponding camera ray.
1262 intrinsics_from:
1263 (*b_shape, 3, 3) the source camera intrinsics
1264 H_c2w_from:
1265 (*b_shape, 4, 4) the homegeneous matrix (source camera -> world)
1266 intrinsics_to:
1267 (*b_shape, *m_shape, 3, 3) the target camera intrinsics
1268 H_c2w_to:
1269 (*b_shape, *m_shape, 4, 4) the homegeneous matrix (target camera -> world)
1270 dim_b:
1271 number of dimensions in b. <= 1
1272
1273 Returns:
1274 (*b_shape, *m_shape, *n_shape, 2) uv, on the images, can be outside of the image boundary.
1275 Note that the pixel center is at x.5, y.5.
1276 The projected uv from each of the *n_shape to each of the *m_shape
1277 """
1278 assert dim_b <= 1, f'only support dim_b = 0 or dim_b = 1'
1279 *bn_shape, _ = uv_c.shape
1280 b_shape = bn_shape[:dim_b]
1281 n_shape = bn_shape[dim_b:]
1282 h, w = z_map.size(-2), z_map.size(-1)
1283 b = np.prod(b_shape)
1284 n = np.prod(n_shape)
1285
1286 # get z_c
1287 z_c = uv_sampling(
1288 uv=uv_c.reshape(b, n, 2),
1289 feature_map=z_map.reshape(b, h, w, 1), # (b, h, w, 1)
1290 uv_normalized=False,
1291 ) # (b, n, dim=1)
1292 z_c = z_c.reshape(*b_shape, *n_shape)
1293
1294 # project to world coord
1295 xyz_w = compute_xyz_w_from_uv(
1296 uv_c=uv_c, # (*b_shape, *n_shape, 2)
1297 z_c=z_c, # (*b_shape, *n_shape)
1298 intrinsic=intrinsics_from, # (*b_shape, 3, 3)
1299 H_c2w=H_c2w_from, # (*b_shape, 4, 4)

Callers

nothing calls this directly

Calls 5

uv_samplingFunction · 0.85
compute_xyz_w_from_uvFunction · 0.85
pinhole_projectionFunction · 0.85
sizeMethod · 0.80
reshapeMethod · 0.45

Tested by

no test coverage detected