MATLAB File Help: cv.reprojectImageTo3D Index
cv.reprojectImageTo3D

Reprojects a disparity image to 3D space

im3d = cv.reprojectImageTo3D(disparity, Q)
[...] = cv.reprojectImageTo3D(..., 'OptionName', optionValue, ...)

Input

Output

Options

The function transforms a single-channel disparity map to a 3-channel image representing a 3D surface. That is, for each pixel (x,y) and the corresponding disparity d=disparity(x,y), it computes:

[X, Y, Z, W]^T = Q * [x, y, disparity(x,y), 1]^T
im3d(x,y,:) = [X/W, Y/W, Z/W]

The matrix Q can be an arbitrary 4x4 matrix (for example, the one computed by cv.stereoRectify). To reproject a sparse set of points {(x,y,d),...} to 3D space, use cv.perspectiveTransform.

Example

The function is similar to the following simplified MATLAB code:

function XYZ = my_reprojectImageTo3D(D, Q)
    [h,w] = size(D);
    XYZ = zeros([h,w,3], 'single');
    for x=1:h
        for y=1:w
            v = Q * [x; y; double(D(x,y)); 1];
            XYZ(x,y,:) = v(1:3) ./ v(4);
        end
    end
end
See also