v9.1.1
Menu

Depth Map Normalization

easyPRODeep Depth EstimationDeep LearningCV: Depth Estimation

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=Z−ZminZmax−ZminZ_{norm} = \frac{Z - Z_{min}}{Z_{max} - Z_{min}}

where:

  • ZminZ_{min} and ZmaxZ_{max} 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

Input
normalize_depth([[1, 2], [3, 4]])
Output
[[0.0, 0.3333], [0.6667, 1.0]]
Reasoning
  • Input: depth_map is a 2×22 \times 2 grid of distances from the camera: [1234]\begin{bmatrix}1 & 2\\ 3 & 4\end{bmatrix}. Larger numbers mean farther away.
  • Range: over the whole map (not per row), Zmin=1Z_{min} = 1 and Zmax=4Z_{max} = 4, so the denominator is Zmax−Zmin=3Z_{max} - Z_{min} = 3.
  • Each pixel: subtract the minimum, then divide by the range. 1−13=0\frac{1-1}{3} = 0, 2−13=13≈0.3333\frac{2-1}{3} = \frac{1}{3} \approx 0.3333, 3−13=23≈0.6667\frac{3-1}{3} = \frac{2}{3} \approx 0.6667, 4−13=1\frac{4-1}{3} = 1.
  • Output: a grid with the same 2×22 \times 2 shape, [[0.0, 0.3333], [0.6667, 1.0]], every value rounded to 4 decimal places. The closest point maps to exactly 00 and the farthest to exactly 11; evenly spaced depths stay evenly spaced.
  • Notice: if every depth were equal, the range would be 00 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

Learn this in

More from CV: Depth Estimation

PRO

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.

solution.py

Test results

Sign in to run your code against the test cases.