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]:
Znormβ=ZmaxββZminβZβZminββ
where:
- Zminβ and Zmaxβ 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]]
Normalizing depth map:
- min = 1, max = 4, range = 3 (1-1)/3 = 0.0 (2-1)/3 = 0.3333 (3-1)/3 = 0.6667 (4-1)/3 = 1.0
Constraints:
- depth_map: 2D array of depth values
- Return normalized depth map with values in [0, 1], rounded to 4 decimal places
- Background Knowledge
Depth maps store the distance from the camera to the scene at each pixel, usually as a 2D array (e.g., a NumPy array) of real numbers. In raw form, these values can be in arbitrary units and ranges (e.g., [0.3, 12.7] meters, or sensor-specific disparity units), which makes them hard to visualize or feed directly into neural networks.
Normalization rescales values into a standard range, commonly [0, 1]. Minβmax normalization does this linearly:
Znormβ=ZmaxββZminβZβZminββThis preserves the relative ordering of depths (closer vs farther) but changes their scale. After normalization:
- Minimum depth becomes 0 (black in grayscale visualization).
- Maximum depth becomes 1 (white).
- All intermediate values are proportionally mapped in between.
In practice, depth normalization is important because many neural network architectures assume inputs roughly in [0, 1] or [-1, 1]. It also prevents large numerical ranges from dominating gradients or causing instability during training.
- Algorithm / Approach
The general pattern here is:
- Scan once over the depth map to find the minimum and maximum values.
- Apply the minβmax formula to each element to map the entire array to [0, 1].
- Handle the degenerate case where all values are identical (so ZmaxββZminβ=0): by definition in this problem, return all zeros.
Conceptually, this is a simple elementwise transformation with precomputed global statistics (min and max).
- Step-by-Step Strategy
Assume the depth map is stored in a 2D array Z (e.g., NumPy, PyTorch, etc.):
- Compute min and max
- Z_min = min(Z) over all pixels.
- Z_max = max(Z) over all pixels.
Continue the full explanation
You're reading the free preview. Unlock the complete walkthrough, the code editor, test runner and reference solution with Premium.
Editor locked
The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.