remove point cloud tilt by plane fit
23 views (last 30 days)
I have a point cloud created from vectors as PCdata = pointCloud([X;Y;Z]'); This represents data from a single plane, with an obvious tilt (2D slope) on it, which I would like to get rid of, so I end up with a point cloud on a horizontal plane.
I managed to fit a plane by:
[model1,inlierIndices,outlierIndices] = pcfitplane(PCdata,100);
...but can anyone tell me how to generate the new point cloud, by either: - subtracting the fitted plane from the original PC = new PC that is at a height around 0 and horizontal ? - subtracting the fitted plane's 2D slope (along x and y) = new PC that is horizontal (but has same mean Z) ?
Any other method you can suggest would also be great, I thought plane fitting would be the obvious way.
Ben Drebing on 4 May 2018
Edited: Ben Drebing on 4 May 2018
I think the fastest way to do this might be to use "pctransform" to rotate your pointcloud. Check out this example:
The only tough part will be defining your rotation matrix (A in the example) and the missing piece of the puzzle is knowing what angles to use to create the matrix. Luckily, the "model1" variable from your plane fit contains a normal vector. This vector basically points "up" in relation to your plane. If you find the angles between this vector and the vector [0,0,1], this will give you the angles needed to rotate the plane until its normal vector is pointing straight up. I thought this link has a pretty good explanation:
Dimitrios Panagiotidis on 2 Apr 2019
Well, I would agree with what Ben said, regarding the trasnformation of your point cloud, however a way that might work is to rotate your point cloud using the CloudCompare software (it is a software particlualrly designed for point clouds processing) or at least you can use it to extract in .txt your tranformation matrix and continue with the rest in Matlab. You can rotate the point cloud there relatively easy, it has many options and a GUI where you can directly see any applied transformation on it: If you wish to do that exclusively in Matlab then consider this example:
theta = pi/2
X = x;
Y = y*cos(theta) - z*sin(theta);
Z = y*sin(theta) + z*cos(theta);
X = x*cos(theta) + z*sin(theta);
Y = y;
Z = z*cos(theta) - x*sin(theta);
X = x*cos(theta) - y*sin(theta);
Y = x*sin(theta) + y*cos(theta);
Z = z;
it wont be an easy task because you need to know the angle for your rotation and also in which axis to apply it :-) that might get lot of time and effort :-) good luck