Surface Integration from Normals
Implement a method to integrate surface normals and recover a depth map, a crucial step in 3D Reconstruction using Photometric Stereo. This process involves calculating the surface gradient from given normals.
The surface gradient is a fundamental concept in Computer Vision, representing the rate of change of the surface depth in the x and y directions. Given the surface normals , , , the surface gradient can be calculated as and , which are essential for integrating the surface.
To integrate the surface, follow these steps:
- Calculate the surface gradient and from the given normals.
- Integrate the gradient to obtain the depth : accumulate along each row (left to right) and down each column (top to bottom), and add the two.
- Shift the result so the mean depth is zero (absolute depth cannot be recovered from normals).
Return a depth map of shape (height, width).
This technique is widely used in 3D scanning and object recognition applications.
Example
Normal map
Depth map
- Input: a normal map where every pixel holds the same unit normal , i.e. a plane tilted only in .
- Gradient: and at every pixel, so depth rises by per step to the right and does not change going down.
- Integrate: accumulating along each row gives ; accumulating down each column adds , so both rows are .
- Centre: the mean depth is , and subtracting it gives , one depth per pixel (shape ).
- Notice that normals only fix slopes, never absolute height, which is why the result is centred on zero. A flat surface (all normals , as in the test) gives and an all-zero depth map.
Constraints
- Input normals: 2D numpy array of shape (height, width, 3) with dtype float32, representing the surface normals , ,
- Valid ranges: values are non-zero, and all normal values are normalized to have a length of 1
- Output depth map: 2D numpy array of shape (height, width) with dtype float32, representing the recovered depth with precision up to 6 decimal places
- Special conditions: The input normals are assumed to be noise-free and the surface is assumed to be Lambertian and convex
- Boundary conditions: The depth values at the boundary of the image are assumed to be zero, and the Poisson equation solver should handle the boundary conditions accordingly