Winner-Take-All Disparity
Find the disparity that minimizes matching cost along an epipolar line.
In stereo matching, we search along the horizontal scanline (after rectification) to find the best matching pixel. The winner-take-all (WTA) strategy selects the disparity with minimum cost:
where is the matching cost (e.g., SAD) at position for disparity .
This function implements a basic scanline stereo algorithm:
- For each candidate disparity from 0 to max_disparity
- Extract a block around in left image
- Extract corresponding block at in right image
- Compute SAD and track minimum
Example
find_disparity([0,0,0,100,100,100,0,0], [100,100,100,0,0,0,0,0], 3, 5, 4)
3
Searching for best disparity at x=4, block_size=3: Left block around x=4: [100, 100, 100] (indices 3,4,5)
- Disparity 0: Right block [0, 0, 0] → SAD = 300
- Disparity 1: Right block [100, 0, 0] → SAD = 200
- Disparity 2: Right block [100, 100, 0] → SAD = 100
- Disparity 3: Right block [100, 100, 100] → SAD = 0 ← minimum! Disparity 4: Right block [100, 100, 100] (would go to index 0)
Best disparity = 3 (perfect match)
Constraints
- left_row: intensity values from left image scanline
- right_row: intensity values from right image scanline
- block_size: width of matching window (odd number)
- max_disparity: maximum disparity to search
- x: center position in left image
- Return disparity with minimum SAD