Search code examples
matlabimage-processingpoint-clouds

How to overlap a point cloud file with another plot in Matlab?


I have a .pcd file of a terrain survey that I opened using this command:

% read point cloud
big_island_cloud = pcread('C:\Users\to\path\Desktop\big_island_5m.pcd');
pcshow(big_island_cloud)

surv

Now I read from a .csv file all necessary columns using readtable in the following way and and verify that everything is fine file(1:3,:) and plot the result using stackedplot:

table

file = readtable('C:\Users\to\path\Desktop\EKF_USBL_CAM_Pose_Projected.csv');
file(1:3,:)
timeStamp = file(:,1);
pose_pose_position_x = file(:,4);
pose_pose_position_y = file(:,5);
stackedplot(file,{'time','field_pose_pose_position_x'});

and the following is what I obtain, pose_pose_position_x is going to be the trajectory I have to draw on top of the .pcd file:

drawing

How do I obtain the following output?:

output

Thank you for shedding light on this matter


Solution

  • Supposing that you have [x,y,z] for the data of your trajectories then you can simply superpose a plot with the use of hold on and plot3:

    Based on the example in the MATLAB documentation :

    numFaces = 600;
    [x,y,z] = sphere(numFaces);
    figure;
    pcshow([x(:),y(:),z(:)]);hold on % keeps the first plot on screen
    plot3([1,1,-1],[1,0.5,1],[1,-0.5,-1]) % adds the trajectory on the plot
    title('Sphere with Default Color Map');
    xlabel('X');
    ylabel('Y');
    zlabel('Z');
    

    Result

    enter image description here

    Edit

    If you only have [x,y] then plot will replace plot3

    plot([1,1,-1],[1,0.5,1]) % adds the trajectory on the plot
    

    Note that the trajectory will be drawn on the plane with z=0