Plane Sweep Stereo
Implement a plane sweep stereo algorithm for multi-view stereo, a technique used in depth estimation to calculate the depth of a scene from multiple images. This task involves sweeping a series of depth planes through the scene to estimate the depth at each point.
The concept of plane sweep stereo relies on the idea of homography, which describes the transformation between two images of the same planar scene. For a given depth plane, the homography matrix can be used to warp all images to a reference view. The photo-consistency of the warped images is then computed, typically using the variance of the pixel values.
Inputs
- images: a list of images of the same size; the first one is the reference view.
- poses: the camera pose matrices (); the first one belongs to the reference view.
- K: the intrinsic matrix shared by all views.
- depths: the candidate plane depths to sweep.
For view , write the relative pose as a rotation and translation , and use the fronto-parallel plane normal . The plane-induced homography at depth is
The warped view at reference pixel takes the pixel of view at after dividing by the third coordinate and truncating to integer pixel coordinates. Locations that fall outside the image read 0. The reference image is used as is.
Here are the general steps to follow:
- Define a series of depth planes to sweep through the scene
- For each depth plane, compute the homography matrix and warp all images to the reference view
- Compute the photo-consistency of the warped images: the per-pixel variance across the images
- For every pixel, return the depth whose variance is smallest (the first such depth on ties)
This technique is widely used in computer vision applications, such as 3D reconstruction and robotics.
Example
Multiple images and poses
Depth map
- Inputs (illustrative): two grayscale views, reference and second view . Focal length , principal point 0, second camera , , depths .
- Homography: with and , is a horizontal shift of : , , pixels for .
- Cost at : the warped view is , since the last two samples fall outside the image. With two views , giving .
- Other planes: gives ; gives .
- Output: each pixel takes its lowest-variance depth, so the depth map is , same height and width as the images.
- Notice: only interior pixels recover the true depth 2. Pixel 6 ties at 900 everywhere, so the first depth wins; pixel 5 drifts to 4 because its match left the image.
Constraints
- Input images: 3D numpy arrays (color or grayscale) with shape (height, width, channels) and pixel values in [0, 255]
- Input poses: 2D numpy arrays with shape (num_views, 4, 4) representing the camera transformation matrices
- Valid depth range: [0, 100] meters, with a minimum and maximum depth plane distance of 0.1 and 10 meters respectively
- Output depth map: 2D numpy array with shape (height, width) and pixel values representing the estimated depth in meters, returned as float32 numpy array
- Assumption: All input images are already undistorted and have the same intrinsic camera parameters