📘
Compute Depth Map from Disparity
MediumDepth Estimation
Given a disparity map, focal length f, and baseline b, compute the depth map using the stereo depth equation.
In a rectified stereo system, depth Z is inversely proportional to disparity d:
Z=df⋅b
where:
- f is the focal length in pixels
- b is the baseline distance between cameras
- d is the disparity (difference in x-coordinates between left and right images)
For zero disparity (no correspondence found), set the depth to infinity (float('inf')).
Return the depth map as a 2D list with values rounded to 4 decimal places.
Example:
Input:
disparity_map = [[10, 20, 0],
[5, 15, 25]]
focal_length = 500.0
baseline = 0.1Output:
[[5.0, 2.5, inf], [10.0, 3.3333, 2.0]]
Reasoning:
- The depth map is computed by applying the stereo depth equation to each element in the disparity map: Z=df⋅b, where f=500.0, b=0.1, and d is the disparity value.
- For each element in the disparity map, we plug in the values into the equation: for the first element, Z=10500.0⋅0.1=5.0; for the second element, Z=20500.0⋅0.1=2.5; and so on.
- When the disparity value is 0 (indicating no correspondence found), the depth is set to infinity: Z=0500.0⋅0.1=∞ or
float('inf'). - The computed depth values are then rounded to 4 decimal places and returned as a 2D list, resulting in the output: [[5.0, 2.5, inf], [10.0, 3.3333, 2.0]].
Constraints:
- disparity_map: 2D list of floats (disparity values >= 0)
- focal_length: float (focal length in pixels)
- baseline: float (baseline distance)
- Return: 2D list of floats (depth values)
- Zero disparity -> float('inf')
- Round to 4 decimal places
- Use pure Python
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.