Disparity Map
An image recording the horizontal pixel displacement (disparity) between corresponding points in a stereo image pair. Depth can be computed from disparity via triangulation, making it an intermediate representation for 3D reconstruction.
A disparity map is the output of stereo matching, storing for each pixel the horizontal offset (disparity) between its position in the left image and its corresponding position in the right image. The relationship between disparity d and depth Z is given by Z = f * B / d, where f is the focal length in pixels and B is the baseline distance between cameras.
Disparity maps are commonly visualized as grayscale images where brighter pixels indicate larger disparity (closer to the camera). They are stored as 16-bit integers or floating-point values for sub-pixel precision. OpenCV's StereoBM and StereoSGBM return values scaled by 16 (fixed-point), so actual disparity requires dividing by 16.
- Nonlinear depth relationship: Since disparity is inversely proportional to depth, depth resolution is high at close range but degrades rapidly at distance. With a 12cm baseline and 700px focal length, a 1-pixel disparity change corresponds to approximately 2mm at 1m but 14cm at 10m
- Occlusion handling: Regions visible in one image but occluded in the other cannot have valid disparity values. Left-right consistency checks detect these invalid pixels, which are then filled by interpolation from neighboring valid values
- Post-processing: WLS (Weighted Least Squares) filtering and median filtering remove noise while preserving depth edges. OpenCV provides
cv2.ximgproc.createDisparityWLSFilter()for edge-aware smoothing of disparity maps
Disparity maps are essential in autonomous driving (obstacle detection and distance estimation), AR/VR (scene understanding and occlusion handling), and robotics (grasp planning and navigation). Commercial depth cameras like Intel RealSense and Stereolabs ZED internally compute disparity maps through hardware-accelerated stereo matching before converting to depth.