Point cloud manipulation along a surface
조회 수: 58 (최근 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
Mathieu NOE
2024년 11월 5일 12:35
hello
do you have some data / code to share ? a picture of your problem ?
답변 (1개)
Ayush
2024년 11월 19일 10:56
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!