How to detect these points in red circle from point cloud. The attached data.txt is the point cloud data. Many thanks.

4 views (last 30 days)
  5 Comments
Yunfeng Ge
Yunfeng Ge on 17 Dec 2019
It made sense. Thanks. But, I want to think out a commen solution. Actually, the background for this problem is how to extract cracks from building surface via 3D point cloud. Now, it can be completed to find out all edges (horizontal and verticle) from point cloud. The horizontal ones are the stairs boundaries, and vertial ones are the cracks. In some case, boundaries and cracks maybe on the same plane (for example road surface).

Sign in to comment.

Accepted Answer

darova
darova on 18 Dec 2019
Here is an idea:
load data.txt
x = data(:,1);
y = data(:,2);
z = data(:,3);
plot3(x,y,z,'.r')
axis equal
datacursormode on
Using daracursormode create two points (data tips) and export coordinates to workspace
123.png
And try this script (find distance from each points to line (two points))
p = cat(1,cursor_info.Position);% extract data
dist = 0.03; % minimum distance to line
v1 = p(1,:)-p(2,:); % vector along line
ind = x*0;
j = 1;
hold on
for i = 1:length(x)
v2 = p(1,:) - [x(i) y(i) z(i)];
v3 = cross(v1,v2);
v4 = cross(v1,v3);
v4 = v4/norm(v4);
D = abs(dot(v2,v4)); % distance to line
if D < dist % if distance is small
ind(j) = i;
j = j + 1;
end
end
ind = ind(1:j-1);
plot3(x(ind),y(ind),z(ind),'ob')
hold off
  3 Comments

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 19 Dec 2019
Try this:
% Initialization / clean-up code.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
data = importdata('data.txt');
x = data(:, 1);
y = data(:, 2);
z = data(:, 3);
subplot(2, 2, 1);
plot3(x, y, z, '.');
grid on;
xlabel('x', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);
zlabel('z', 'FontSize', fontSize);
% Get the 3 sets based on the x values. These are indexes.
set1 = x <= 2;
set2 = x > 2 & x <= 2.5;
set3 = x > 2.5;
% Get the (x, y, z) coordinates for set #1;
x1 = x(set1);
y1 = y(set1);
z1 = z(set1);
% Get the (x, y, z) coordinates for set #1;
x2 = x(set2);
y2 = y(set2);
z2 = z(set2);
% Get the (x, y, z) coordinates for set #1;
x3 = x(set3);
y3 = y(set3);
z3 = z(set3);
% Plot the 3 sets in different colors.
subplot(2, 2, 2);
plot3(x1, y1, z1, 'r.');
hold on;
plot3(x2, y2, z2, 'g.');
plot3(x3, y3, z3, 'b.');
grid on;
xlabel('x', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);
zlabel('z', 'FontSize', fontSize);
% Get the z thresholds for each set.
zMin1 = min(z1)
zMax1 = max(z1)
zMin2 = min(z2)
zMax2 = max(z2)
zMin3 = min(z3)
zMax3 = max(z3)
% Trim set #1.
margin = 0.05 * abs(zMax1 - zMin1);
goodZ = z1 < (zMax1 - margin) & z1 > (zMin1 + margin);
x1 = x1(goodZ);
y1 = y1(goodZ);
z1 = z1(goodZ);
goodY = y1 > -0.3 & y1 < -0.2;
x1 = x1(goodY);
y1 = y1(goodY);
z1 = z1(goodY);
% Trim set #2.
margin = 0.05 * abs(zMax2 - zMin2);
goodZ = z2 < (zMax2 - margin) & z2 > (zMin2 + margin);
x2 = x2(goodZ);
y2 = y2(goodZ);
z2 = z2(goodZ);
margin = 0.05 * abs(zMax3 - zMin3);
% Trim set #3.
goodZ = z3 < (zMax3 - margin) & z3 > (zMin3 + margin);
x3 = x3(goodZ);
y3 = y3(goodZ);
z3 = z3(goodZ);
% Plot the 3 sets in different colors.
subplot(2, 2, [3,4]);
plot3(x1, y1, z1, 'r.');
hold on;
plot3(x2, y2, z2, 'g.');
plot3(x3, y3, z3, 'b.');
grid on;
xlabel('x', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);
zlabel('z', 'FontSize', fontSize);
0000 Screenshot.png
Adjust parameters as needed.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!