| MIL 10 User Guide
| Customize Help

Operations on depth maps



See also
Availability
Not available in MIL-Lite

Available in MIL
Next

If you have a depth map of a scene, you can perform arithmetic operations on this map or process it to obtain geometric and statistical information about it.

Fitting a plane to the depth map

It is possible to fit a horizontal plane or an arbitrary plane to a depth map, using M3dmapSetGeometry() with M_FIT; when calling M3dmapSetGeometry(), you must also pass a MIL geometry object, which you must allocate using M3dmapAlloc() with M_GEOMETRY. You can then inquire the coefficients of the equation of the fitted surface, in world units, using M3dmapInquire() with M_FIT_.... It is also possible to obtain the root-mean-squared error of the fit operation using M3dmapInquire() with M_FIT_RMS_ERROR.

Optionally, you can supply an outlier distance and a mask image to M3dmapSetGeometry() to ignore certain depth map pixels during the fit operation. The mask image buffer must be a binary, 8-bit or 16-bit 1-band buffer and must have the same dimensions as the depth map. Any depth map pixel whose corresponding mask image pixel is set to 0 will be ignored during the fit operation.

Note that M3dmapSetGeometry() with M_FIT fits the plane to all unmasked depth map pixels that are not outside the outlier distance. If your depth map image represents objects of different heights or an object with gaps in height, you should leave unmasked only objects (or parts of objects) with a similar height or a smooth transition in height; otherwise, you will obtain unpredictable results.

Besides fitting a plane, you can also explicitly define a plane, using M3dmapSetGeometry() with M_PARAMETRIC and the coefficients of the equation of the required plane. This can be useful in conjunction with statistical or arithmetic operations. For example, you can define a plane parametrically and subtract it from a depth map using M3dmapArith(). Since a parametrically defined horizontal plane corresponds to a known height, this would allow you to subtract a known height from your depth map.

You can draw the depth map of a fitted or defined plane, using M3dmapDraw() with M_DRAW_GEOMETRY. This can be useful, for example, to visualize the plane, or perform depth map arithmetic operations.

Computing statistics

Various statistical results can be obtained from a depth map using M3dmapStat(). Optionally, this function can take a depth map or a fitted or defined plane as a reference level, instead of using the XY-plane (Z=0) as the reference level. This can be useful, for example, if you want to calculate statistics for the volume between two depth maps or between a depth map and its fitted plane.

M3dmapStat() can compute statistics such as the maximum and mean height deviation with respect to the reference level, as well as the volume. For added flexibility, you can apply a mask and specify an outlier distance. For example, you can use a mask image with a volume calculation to calculate the volume of a certain area in the depth map.

You can also exclude all depth map pixels above or below the reference level, or treat all vertical distances as positive, using one of the M_STAT_... combination constants. All statistics are calculated in the relative coordinate system (which is initially aligned with the 3D reconstruction coordinate system) and are returned in world units. Note that when treating only depth map pixels below the reference level (M_STAT_NEGATIVE), statistics are measured in the negative Z-direction, so all results are positive. For example, given the following depth map values:

The basic M_DEVIATION_MEAN statistics calculation with its four possible combination flags are as follows:

M_DEVIATION_MEAN + M_STAT_POSITIVE

( (+1) + (+1)) / 2 = 1

M_DEVIATION_MEAN + M_STAT_NEGATIVE

( |-1| + |-3|) / 2 = 2

M_DEVIATION_MEAN + M_STAT_ALL

( (+1) + (-1) + (+1) + (-3)) / 4 = -0.5

M_DEVIATION_MEAN + M_STAT_ABS

( |+1| + |-1| + |+1| + |-3|) / 4 = 1.5

You can determine the number of pixels taken into account when computing statistics, using M_NUMBER_OF_PIXELS_VALID.

Performing arithmetic operations on depth maps

You can perform arithmetic operations between depth maps and fitted or defined planes using M3dmapArith(), to produce a new depth map. Supported operations include addition, subtraction, and minimum/maximum operations. This could be useful to, for example, subtract a fitted plane from the depth map to find the regions which deviate from the fit.

All image operands must be fully corrected depth maps for this operation. To determine if you have a fully corrected depth map, call McalInquire() with M_GRAY_LEVEL_SIZE_Z and ensure that it does not return M_INVALID_SCALE.