MCPcopy Create free account
hub / github.com/NVlabs/InstantSplat / transform_poses_pca

Function transform_poses_pca

utils/pose_utils.py:257–292  ·  view source on GitHub ↗

Transforms poses so principal components lie on XYZ axes. Args: poses: a (N, 3, 4) array containing the cameras' camera to world transforms. Returns: A tuple (poses, transform), with the transformed poses and the applied camera_to_world transforms.

(poses)

Source from the content-addressed store, hash-verified

255 return p[..., :3, :4]
256
257def transform_poses_pca(poses):
258 """Transforms poses so principal components lie on XYZ axes.
259
260 Args:
261 poses: a (N, 3, 4) array containing the cameras' camera to world transforms.
262
263 Returns:
264 A tuple (poses, transform), with the transformed poses and the applied
265 camera_to_world transforms.
266 """
267 t = poses[:, :3, 3]
268 t_mean = t.mean(axis=0)
269 t = t - t_mean
270
271 eigval, eigvec = np.linalg.eig(t.T @ t)
272 # Sort eigenvectors in order of largest to smallest eigenvalue.
273 inds = np.argsort(eigval)[::-1]
274 eigvec = eigvec[:, inds]
275 rot = eigvec.T
276 if np.linalg.det(rot) < 0:
277 rot = np.diag(np.array([1, 1, -1])) @ rot
278
279 transform = np.concatenate([rot, rot @ -t_mean[:, None]], -1)
280 poses_recentered = unpad_poses(transform @ pad_poses(poses))
281 transform = np.concatenate([transform, np.eye(4)[3:]], axis=0)
282
283 # Flip coordinate system if z component of y-axis is negative
284 if poses_recentered.mean(axis=0)[2, 1] < 0:
285 poses_recentered = np.diag(np.array([1, -1, -1])) @ poses_recentered
286 transform = np.diag(np.array([1, -1, -1, 1])) @ transform
287
288 # Just make sure it's it in the [-1, 1]^3 cube
289 scale_factor = 1. / np.max(np.abs(poses_recentered[:, :3, 3]))
290 poses_recentered[:, :3, 3] *= scale_factor
291 transform = np.diag(np.array([scale_factor] * 3 + [1])) @ transform
292 return poses_recentered, transform
293
294
295def recenter_poses(poses: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:

Callers 1

generate_ellipse_pathFunction · 0.70

Calls 2

unpad_posesFunction · 0.70
pad_posesFunction · 0.70

Tested by

no test coverage detected