Point cloud manipulation along a surface
8 次查看(过去 30 天)
显示 更早的评论
Hi all
I'm trying to remove parts from a point cloud.
Its easy enogh to reomve items when working in 2d i can just use the find command and remove all point <> a certain value.
the diffulculty im having is when i dont want to remove points along a stright line say for example a had a curve and i wish to remove all points below that spline. which then when i move into 3d and the "cutting" line is a 3d curved surface.
can anyone shere some advice on techniques i can try ?
Oh im also stuck in 2018b
thanks
tim
2 个评论
回答(1 个)
Ayush
2024-11-19
Hi Tim,
I understand that you need to work with point clouds, and it can get little challenging when you want to selectively remove points based on some complex geometric criteria.
Here is a standard workflow which you can follow for removing points from a point cloud:
- You can fit a spline to your curve using “spline” or “csaps”. Try evaluating the spline at your desired x-values to determine the y-values of the curve and remove points that fall below these y-values.
You can read more about “spline” function here: https://www.mathworks.com/help/matlab/ref/spline.html
You can read more about “csaps” function here:
2. You can also use “fit” from the curve fitting toolbox or “griddata” for interpolation to create a surface fit.
You can read more about “fit” and “griddata” functions here:
3. Once you have the fit or surface, you can use logical indexing to remove points. For example, in 2D, you can do as follows:
y_fit = ppval(splineFit, x);
pointsToKeep = y >= y_fit; % Logical index for points above the curve
x = x(pointsToKeep);
y = y(pointsToKeep);
4. If you have computer vision toolbox, you can also use functions like “pcfitplane” to fit geometric shapes to your point cloud. Also, you can write custom function to iterate over each point and determine its position relative to your curve or surface.
You can read more about “pcfitplane” function here: https://www.mathworks.com/help/vision/ref/pcfitplane.html
Here is a MATLAB code for your reference:
% Generate sample 3D point cloud data
numPoints = 1000;
x = rand(numPoints, 1) * 10;
y = rand(numPoints, 1) * 10;
z = sin(x) + cos(y) + randn(numPoints, 1) * 0.1;
% Fit a surface using scatteredInterpolant
F = scatteredInterpolant(x, y, z, 'natural', 'linear');
% Create a grid to evaluate the surface
[xq, yq] = meshgrid(linspace(0, 10, 100), linspace(0, 10, 100));
zq = F(xq, yq);
% Remove points below the surface
z_surface = F(x, y);
pointsToKeep = z >= z_surface;
x_filtered = x(pointsToKeep);
y_filtered = y(pointsToKeep);
z_filtered = z(pointsToKeep);
% Plot the original and filtered point cloud
figure;
subplot(1, 2, 1);
scatter3(x, y, z, 'b.');
hold on;
mesh(xq, yq, zq, 'EdgeColor', 'r', 'FaceAlpha', 0.3);
title('Original Point Cloud with Surface');
xlabel('X');
ylabel('Y');
zlabel('Z');
view(3);
grid on;
subplot(1, 2, 2);
scatter3(x_filtered, y_filtered, z_filtered, 'g.');
hold on;
mesh(xq, yq, zq, 'EdgeColor', 'r', 'FaceAlpha', 0.3);
title('Filtered Point Cloud');
xlabel('X');
ylabel('Y');
zlabel('Z');
view(3);
grid on;
Hope it helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Point Cloud Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!