Depth Map Normalization
Normalize a depth map to [0, 1] range using min-max normalization.
Depth maps often need normalization for visualization or as input to neural networks. Min-max normalization maps values to [0, 1]:
where:
- and are the minimum and maximum depths in the map
- Closest points (small Z) become 0 (black in visualization)
- Farthest points (large Z) become 1 (white in visualization)
Note: If all depths are equal, the normalized result is all zeros.
Example
normalize_depth([[1, 2], [3, 4]])
[[0.0, 0.3333], [0.6667, 1.0]]
- Input:
depth_mapis a grid of distances from the camera: . Larger numbers mean farther away. - Range: over the whole map (not per row), and , so the denominator is .
- Each pixel: subtract the minimum, then divide by the range. , , , .
- Output: a grid with the same shape,
[[0.0, 0.3333], [0.6667, 1.0]], every value rounded to 4 decimal places. The closest point maps to exactly and the farthest to exactly ; evenly spaced depths stay evenly spaced. - Notice: if every depth were equal, the range would be and the fraction undefined, which is why the description asks for an all-zeros map of the same shape in that case.
Constraints
- depth_map: 2D array of depth values
- Return normalized depth map with values in [0, 1], rounded to 4 decimal places