Post Go back to editing

Point cloud or depth map export to Matlab

I use AD-96TOF1-EBZ (with dragonboard)

Is it possible to get the point cloud exported to Matlab?

The "aditof_imaq.m" Matlab example and the built-in "image acquisition tool" work well. The depth map image and IR image stream is nice, but I miss data stream/export. In special the point cloud or depth map data.

Thanks for help :-)!

  • It should be possible to export both the depth map and the IR data to MATLAB by saving the frames in an array, which can be afterwards used for further processing.

    The depth map which comes from the camera is already compensated to take into account the camera's intrinsic values, so it can be used directly to display the point cloud. 

  • Thank you for your answer! I saw, that the depth map image can be exported in RGB, YCbCr or Grayscale format. The number representation is uint8, so for Grayscale I get just 256 values (0-255) in a 2D array. Isn't that a loss of precision?

    And what would be the correct scale value, to convert 0-255 to the correct distance? Is this scale value different for near/medium/far mode?

    In the provided aditof_sdk-2.0.0/bindings/matlab I find a textfile "colormap.txt", should this be used to convert a RGB depth map in to depth map with distance values? Again the scale value is unclear.

  • Hello,

    Using the second matlab script (version B) we were able to obtain the following results without any modifications:

  • that looks promising! how did you made the depth map image? also with the matlab example "aditof-imaq.m"? and how did you exactly exported it (RGB, Grayscale, YPbBr, as Mat-File, Image-File,..)? Thank you very much!
    I have used aditof-imaq.m and exported depthMap as Grayscale in Mat-File format.

  • Using aditof-imaq.m and export depthMap as RGB (it is the default mode) in MAT-File.

  • That wonders me. I wrote the conversion for Grayscale depthMaps. It handels MxNx1 arrays. The depth is read out in line 37 as the grayscale value directly. But as you exported it as RGB (MxNx3), how can you use this Matlab-Code without any modifications, because I expect then just the first color (red) will be interpreted as depth?

  • May you please repeat my measurement (near-mode) of a box in ~40cm distance and present your RGB and Grayscale depth map and converted point cloud? Because I see circles (RGB and Grayscale), when I measure a flat surface. As I understand, this means the distance is from the middlepoint of the camera and a conversion is therefore necessary...

  • Hello, we will update the script and come back with an answer as soon as possible.

  • Hello, to begin with, please checkout at the latest master.

    After you run aditof_imaq.m please export the data as MONO16 and select RawDepth format.
    After that you ca run the following script and the data should look alright.

    %% Convertion depth map into point cloud - version B
    close all; clear all; clc
    % Range: <6m
    % FoV: 90° x 69.2°
    % Near: 25cm – 80cm
    % Medium: 30cm – 4.5m
    % Far: 3m – 6m
    % Resolution: 640 x 480 pixels
    s = load('depthMat.mat');
    p = s.depth; % uint8
    depthMap = double(p)+1; % uint8 to double
    % FOVhDeg = 90;
    % FOVhRad = deg2rad(FOVhDeg);
    n_c = 640;
    % FOVvDeg = 69.2;
    % FOVvRad = deg2rad(FOVvDeg);
    n_r = 480;
    xyzPointsFromDepthMap = zeros(n_c*n_r,3);
    for yPixel = 1:480
        for xPixel = 1:640     
            % Calculate x-coordinate
            xyzPointsFromDepthMap(i,1) = xPixel; % x value
            % Calculate y-coordinate
            xyzPointsFromDepthMap(i,2) = yPixel; % y value
            % Calculate z-coordinate
            xyzPointsFromDepthMap(i,3) = depthMap(yPixel,xPixel) / 10; % z value
            i = i+1;
    ptCloud = pointCloud(xyzPointsFromDepthMap);
    %% Plot point cloud
    title('ToF point cloud from depth map')
    set(gca, 'Zdir', 'reverse')
    title('ToF point cloud from depth map')
    set(gca, 'Zdir', 'reverse')

    Best regards,

  • After I run aditof_imaq.m, the image acquisition toolbox opens automatically. There I see no option to export it as MONO16, neither RawDepth format

    The changes you made in the script (1. divide depth by 10, and 2. flip the z-axis), I unfortunately do not understand why that should solve my distortion problem..

    I am very thankful for your help! But now I have invested so many hours in that.. and still many open, unanswered questions (like: is the depth shown in the depthMap the distance to the center-point of the camera or to the xy-plane?).

  • Hello, please use the latest master from and not the v2.0.0 since there were updates made since that release one of which is the update for matlab.

    The distance division was required so that the space would't be altered and the shown distance would be in cm. The inversion of axis was required so that the points at a higher distance would be represented in the background plane. 

Reply Children