To convert a pixel to a 3D ray, you “undo” the camera intrinsics: map image coordinates back into the camera’s 3D coordinate frame and then normalize that vector.
1. Background Knowledge
In the pinhole camera model, a 3D point in the camera frame \mathbf{X}c=(X,Y,Z)⊤ projects to a pixel (u,v) via the intrinsic matrix K. In homogeneous coordinates:
λuv1=KXYZ,
where K encodes focal lengthsfx,fy and principal point(cx,cy). This is the forward projection: 3D → 2D.
The inverse operation is what you need here: given pixel (u,v), find the ray in 3D that passes through that pixel. Every pixel corresponds to all 3D points lying along a ray starting at the camera center and passing through that image point. In the camera frame, this ray can be represented by a direction vector\hat{\mathbf{r}}; since only direction matters, we usually normalize it to unit length.
2. Algorithm / Approach
General pattern:
Represent the pixel in homogeneous image coordinates: (u,v,1)⊤.
Apply the inverse intrinsicsK−1 to map this into the camera frame:
r=K−1uv1.
Interpret r=(rx,ry,rz)⊤ as a 3D direction in the camera frame.
Normalize to get a unit ray direction:
r^=∥r∥r.
For the simplified intrinsics with no skew and no distortion, this becomes direct arithmetic on (u,v), using fx,fy,cx,cy.
3. Step‑by‑Step Strategy
Assume intrinsics:
K=fx000fy0cxcy1.
Step 1: Subtract principal point and divide by focal length
Compute the unnormalized ray components:
rx=fxu−cx
ry=fyv−cy
rz=1
So:
r=rxry1.
PRO
Continue the full explanation
You're reading the free preview. Unlock the complete walkthrough, the code editor, test runner and reference solution with Premium.
PRO
Editor locked
The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.