3D visionExplainer

Stereo disparity scale and calibration for depth estimates

Resolve stereo disparity scale and calibration by checking raw encoding, rectified focal length, baseline units, and depth estimates.

LumaSpec Vision10 min read Share on LinkedIn

On this page 10 sections
  1. 011. Establish what the disparity image actually contains
  2. 022. Obtain focal length and baseline from matching calibration
  3. 033. Apply the depth equation in rectified coordinates
  4. 044. Work through an illustrative conversion
  5. 055. Keep resizing and cropping consistent
  6. 066. Verify against several known distances
  7. 077. Read the error pattern before changing parameters
  8. 088. Choose an interface that exposes the required data
  9. 099. Check these items before accepting the conversion
  10. 10Questions

A disparity image is not necessarily a map of pixel distances stored directly as integers. It may contain scaled values, reserved invalid codes, or coordinates tied to a particular rectified image stream. Applying a depth equation before checking those details can produce believable but incorrect measurements.

For engineers converting stereo output into depth, the first decision is which documented data contract to use. You need the disparity encoding, matching rectified calibration, and an explicit coordinate convention. The workflow below separates those requirements and shows how to validate the conversion against known distances.

1. Establish what the disparity image actually contains

Start with the official documentation and API reference for the installed firmware and software versions. Confirm that the selected output is disparity rather than depth, confidence, or a display visualization. A colored preview cannot establish the numerical meaning of the underlying buffer.

Record these properties before calculating anything:

  • Pixel format, numeric type, byte order, and row stride.
  • Disparity scale and any additive encoding offset.
  • Invalid, saturated, and out-of-range codes.
  • Left-reference or right-reference image convention.
  • Whether the stream is rectified, resized, cropped, or otherwise processed.
  • The calibration object associated with that exact stream profile.

An unsigned 16-bit buffer provides storage capacity, not a disparity specification. Its largest observed value might represent a valid measurement, a reserved code, or a decoding mistake. Do not infer the scale from the data type or maximum value alone.

A common fixed-point representation can be described as:

d = (r - o) / s

Here, r is the stored code, o is an encoding offset in code units, and s is the number of code units per disparity pixel. The decoded disparity d is measured in pixels. This is a representation to verify, not a universal camera convention.

For example, documentation might specify 16 code units per pixel. That would make a stored code of 1536 equal to 96 pixels when the encoding offset is zero. Another interface could return floating-point pixels directly.

If the buffers or metadata are uncertain, begin with checking raw stereo streams and their calibration metadata.

2. Obtain focal length and baseline from matching calibration

The focal length needed for stereo depth is normally the horizontal focal length of the rectified image, expressed in pixels. It is not the lens focal length in millimeters, a field-of-view estimate, or an intrinsic value from a different image profile.

Use the official API or calibration export to obtain:

  • The rectified horizontal focal length.
  • The horizontal principal point of each rectified image.
  • The relative camera translation or documented stereo baseline.
  • The coordinate units and transform direction.
  • The image dimensions and processing profile to which these values apply.

A baseline entered in millimeters produces depth in millimeters when focal length and disparity use the same pixel coordinate system. A baseline entered in meters produces depth in meters. Display resolution does not determine either calibration value.

Some interfaces provide rectified projection matrices rather than a separate baseline field. Under the conventional horizontal stereo model, with the left camera as origin and the right camera displaced along positive horizontal position:

P_right[0, 3] = -f_x × B B = -P_right[0, 3] / P_right[0, 0]

This extraction applies only when the matrix follows that documented convention. Do not remove signs blindly or substitute the translation magnitude without checking how the rectified matrices were constructed.

When moving parameters between software packages, checking calibration formats and coordinate conventions helps prevent a correct value from being interpreted incorrectly.

3. Apply the depth equation in rectified coordinates

For a conventional horizontal rectified pair, define disparity as the left horizontal coordinate minus the matching right horizontal coordinate:

d = u_left - u_right d_effective = d - (c_x_left - c_x_right) Z = f_x × B / d_effective

The symbols have specific meanings:

Quantity Meaning Required units
d Decoded horizontal disparity Pixels
c_x_left, c_x_right Rectified horizontal principal points Pixels
f_x Rectified horizontal focal length Pixels
B Baseline under the stated convention Chosen length unit
Z Depth along the rectified optical axis Same length unit as baseline

When the rectified principal points are equal, the correction disappears and the familiar equation becomes Z = f_x × B / d. However, equal principal points must come from the calibration or documented rectification settings, not an assumption.

Some APIs already return a disparity quantity with principal-point correction included. Applying that correction again would introduce an error. Keep encoding offsets separate from geometric offsets, and follow the documented meaning of the output.

Where available, a documented reprojection matrix or official conversion function can handle these conventions more reliably than a handwritten scalar equation. It still needs the matching disparity representation and image geometry.

Also distinguish axial depth from straight-line range. Z measures position along the optical axis. A point near the image edge can have a longer distance from the camera origin despite sharing the same axial depth as a central point.

4. Work through an illustrative conversion

Consider a hypothetical calibrated stream with these values. They are arithmetic examples, not specifications for any product:

  • Stored disparity code: 1536.
  • Encoding offset: 0 code units.
  • Scale: 16 code units per pixel.
  • Rectified horizontal focal length: 800 pixels.
  • Baseline: 120 mm.
  • Equal rectified horizontal principal points.

The conversion is:

d = (1536 - 0) / 16 = 96 pixels Z = 800 × 120 / 96 = 1000 mm

Using the same baseline as 0.120 m gives:

Z = 800 × 0.120 / 96 = 1.000 m

The result describes the same position. Unit consistency changes the numerical representation, not the geometry.

If you mistakenly treated the stored code as pixels, the calculation would instead give:

Z_wrong = 800 × 120 / 1536 = 62.5 mm

The estimated depth would be too small by a factor of 16. This constant-factor signature is useful, but it does not prove that disparity scaling is the cause. A baseline-unit error or mismatched focal length can also produce systematic scale errors.

Now consider a second valid code of 768 under the same assumptions:

d = 768 / 16 = 48 pixels Z = 800 × 120 / 48 = 2000 mm

Halving effective disparity doubles depth. Use that inverse relationship as a sanity check, rather than expecting disparity values to increase with distance.

5. Keep resizing and cropping consistent

Calibration belongs to an image coordinate system. Resizing only the disparity array, or borrowing focal length from a different output resolution, breaks that relationship.

For a simple horizontal resize with scale factor a, corresponding focal length and disparity scale together:

f_x_new = a × f_x_old d_new = a × d_old

The ratio remains unchanged when both quantities are transformed consistently. For example, halving an 800-pixel focal length and a 96-pixel disparity gives 400 pixels and 48 pixels. Both combinations produce the same depth with the same baseline.

However, resizing a disparity image as an ordinary numeric array does not necessarily rescale the disparity values. That depends on the operation or API. Invalid pixels also require deliberate handling during interpolation.

Cropping changes the principal-point coordinates. Different crop origins for the left and right images also change the disparity coordinate relationship. Prefer calibration and reprojection data supplied for the processed output instead of reconstructing those adjustments from memory.

Before reusing saved data, follow the checks for confirming that recorded stereo frames are rectified. If correspondence itself is unreliable, use diagnosing a disparity map after rectification before tuning the depth conversion.

6. Verify against several known distances

A single target position cannot reliably distinguish encoding, geometry, and measurement-reference errors. Use several distances across the intended operating range and preserve the raw buffers alongside their metadata.

  1. Place a flat, textured target approximately perpendicular to the optical axis.
  2. Establish its axial distance from the documented camera coordinate origin, not an arbitrary housing surface.
  3. Select a central region away from target edges, glare, and occlusions.
  4. Decode valid disparity samples and calculate depth for each sample.
  5. Report the median depth, valid-pixel fraction, and a spread statistic.
  6. Repeat at no fewer than three distances and compare measured depth against the references.

For a hypothetical test at 0.8 m, 1.2 m, and 1.8 m, calculate both absolute error and measured-to-reference ratio. A nearly constant ratio suggests a multiplicative mismatch. A roughly constant distance offset suggests a reference-origin issue, although neither pattern is conclusive alone.

Depth calculated from median disparity is not generally identical to median calculated depth for every aggregation method or sample distribution. Define the statistic and keep it consistent throughout validation.

If the API offers an official depth output, compare it with your conversion from the same acquisition and processing stage. Differences become harder to interpret when one path adds filtering, temporal processing, or hole filling.

For errors that affect the whole measurement scale, diagnosing depth-scale mismatches provides a related set of checks.

7. Read the error pattern before changing parameters

Use the observed behavior to choose the next test, rather than adjusting focal length until one target looks correct.

Observed pattern Likely checks Useful next test
All depths differ by a similar factor Encoding scale, baseline units, focal length Compare documented units and repeat at multiple distances
Error changes after switching image profile Calibration-profile mismatch Retrieve calibration for the active stream again
Many isolated points appear extremely close Invalid codes, saturation, decoding Inspect raw codes and validity masks at those pixels
Error grows disproportionately with distance Additive disparity error, correspondence uncertainty Compare effective disparity against reference distance
Depth changes across a flat target unexpectedly Rectification, principal points, target alignment Inspect correspondences and calibrated reprojection
Results change after image resizing Pixel-coordinate mismatch Trace focal length and disparity transformations

Even with correct scaling, depth uncertainty increases as disparity becomes smaller. For disparity uncertainty alone, a first-order estimate is:

sigma_Z ≈ (f_x × B / d_effective²) × sigma_d

Using the earlier illustrative geometry and a disparity uncertainty of 0.25 pixels gives approximately 2.6 mm depth uncertainty at 1000 mm. At 2000 mm, the same disparity uncertainty gives approximately 10.4 mm.

These figures are sensitivity estimates, not accuracy guarantees. Calibration errors, surface reflectance, occlusion, motion, and correspondence bias add other contributions. Fixed-point storage increments are also not equivalent to measurement accuracy.

8. Choose an interface that exposes the required data

When comparing 3D sensors, start with the required output rather than the broad sensing category. A system that delivers a usable point cloud may not expose raw disparity, rectified images, or calibration matrices through its supported interface.

The camera finder helps narrow hardware candidates. Before committing to a custom conversion, request confirmation of disparity access, encoding documentation, calibration retrieval, and supported software versions.

The MV-DLS300P-04 is cataloged as a laser galvanometer stereo camera. Its listing alone does not establish access to the disparity representation discussed here.

3D sensorsHikrobot MV-DLS300P-04 Laser galvanometer stereo cameraMV-DLS300P-04
Type
Stereo / structured light
$16,579.00 · quotedView and quote

The MV-DPS200P-02 is cataloged as a projected structured-light camera. Confirm its documented outputs against your integration requirements rather than assuming a shared API across sensing methods.

3D sensorsHikrobot MV-DPS200P-02 Projected structured-light 3D cameraMV-DPS200P-02
Type
Stereo / structured light
$8,829.00 · quotedView and quote

For either candidate, obtain software and documentation through the manufacturer or its authorized distributors. Ask for a supported example that retrieves calibration for the selected stream and identifies invalid output values.

If your application only requires calibrated depth, an official depth interface may be the better choice. Raw disparity conversion is useful when you need correspondence diagnostics, research access, or control over downstream reconstruction. It is not automatically more accurate.

9. Check these items before accepting the conversion

Use this short acceptance checklist before integrating the calculation into inspection logic:

  • Encoding confirmed: scale, offset, numeric format, and invalid codes come from official documentation.
  • Profile matched: disparity and calibration describe the same acquisition and processing geometry.
  • Coordinates defined: reference image, disparity sign, principal points, and transform direction are explicit.
  • Units recorded: baseline units determine the reported depth units.
  • Invalid values preserved: missing correspondence remains invalid rather than becoming a fabricated distance.
  • Validation completed: multiple known distances show acceptable bias and repeatability.
  • Processing traced: resizing, cropping, filtering, and software changes are documented.
  • Failure behavior defined: downstream logic can reject insufficient valid data instead of using an unreliable measurement.

The usual scalar equation is the wrong starting point when the output is already depth, the stereo geometry is not horizontal and rectified, or the API defines a different coordinate convention. Use the documented reprojection path in those cases.

For hardware selection, start with the camera configuration step. For conversion support, send the active stream profile, encoding description, calibration fields, and reference-distance results through technical support.

Questions

Does a 16-bit disparity image reveal its scale?

No. The storage type only defines which codes fit in the buffer. Disparity may use fixed-point scaling, floating-point pixels, an encoding offset, or reserved invalid values. Identify the format through the official API or documentation before converting codes into pixel disparity.

Which focal length belongs in the stereo depth equation?

Use the horizontal focal length associated with the rectified disparity stream, normally expressed in pixels. A physical lens focal length in millimeters cannot be substituted directly. Check that the calibration matches the active resolution, crop, and processing profile.

Can I measure the baseline from the camera housing?

Retrieve the documented calibrated baseline or derive it from projection data using the stated coordinate convention. Housing dimensions do not necessarily locate the optical coordinate origins. An approximate mechanical measurement is useful for a sanity check, not as a replacement for calibration.

Why does depth error increase farther from the camera?

Small disparities make depth more sensitive to correspondence errors. An additive disparity bias can therefore create increasingly large distance errors even when one nearby target appears correct. Test several reference positions and inspect calibration, principal-point conventions, and matching quality before changing scale.

Should I use raw disparity instead of the official depth output?

Choose raw disparity when the application needs correspondence analysis or a custom reconstruction pipeline. Otherwise, documented depth output can reduce integration work by handling encoding and reprojection internally. Validate either output against your task requirements, and confirm which processing stages each interface applies.