MATLAB Answers

Divided interest of space (ROI) into continuous cubes

46 views (last 30 days)
Ehsan Shooshtari
Ehsan Shooshtari on 2 Aug 2020 at 16:13
Edited: Ehsan Shooshtari about 7 hours ago
Hello
Dear Friends
I have a Lider result consist of X, Y, Z in matlab file and for each cell/frame I want to divide the region of interest (ROI) space (X: -150m to 150m; Y:-100m to 100m; Z: -15m to 15m) into continuous cubes (0.1m cube length) and calculate the point density in each cube.
clc
close all
fileDir = 'D:\Examps'; % the target data directory
%outfile = 'D:\XYZ_14000.csv';
fid=fopen(outfile,'w');
d=dir(fullfile(fileDir,'*.csv')); % dir() struct of *.csv files in directory
N=numel(d); % total number files found
for i = 1:N % iterate over them...
XYZ=readmatrix(fullfile(fileDir,d(i).name),'NumHeaderLines',1);
data=XYZ(:,1:3); % select the three columns only
fmt=[repmat('%f,',1,numel(data)-1) '%f\n'];
fprintf(fid,fmt,data);
X=XYZ(1:4,1);
Y=XYZ(1:4,2);
Z=XYZ(1:4,3);
% if -100<=X<=100
% X=Xlimit
%else X'='0
end
fid=fclose(fid);
Thanks

  0 Comments

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 2 Aug 2020 at 23:13
Description
labels = segmentLidarData(ptCloud,distThreshold) segments organized 3-D range data ptCloud into clusters. The function assigns an integer cluster label to each point in the point cloud and returns the cluster label of all points in labels.
The function groups two neighboring points into the same cluster if their Euclidean distance is less than distThreshold or if the angle between the sensor and two neighboring points is at least 5 degrees.

  2 Comments

Ehsan Shooshtari
Ehsan Shooshtari on 3 Aug 2020 at 0:53
Hello Dear
Thanks for response
First: I have a threshold for X, Y, Z and labels = segmentLidarData(ptCloud,distThreshold) just accept a simple threshold 5 without mention X,Y,Z.
Second: I added below script and still doesn't show any things.(like my script is not mach by the rest)
% Specify limits of point cloud display
xlimits = [-150 150]; % meters
ylimits = [-100 100];
zlimits = [-15 15];
pc = pointCloud(cat(3,X,Y,Z));
figure
pcshow(pc.Location,'r')
title('Unclustered Point Cloud')
Regards
Ehsan Shooshtari
Ehsan Shooshtari about 7 hours ago
Hello
Dear Friends
I need some clue to handle my rest, consist of
1- calculate the point density in each cube.
2- background filtering.
clc
close all
fileDir = 'D:\Examps2'; % the target data directory
outfile = 'D:\100Frames.las';
fid=fopen(outfile,'w');
d=dir(fullfile(fileDir,'*.csv')); % dir() struct of *.csv files in directory
N=numel(d); % total number files found
for i = 1:N % iterate over them...
XYZ=readmatrix(fullfile(fileDir,d(i).name),'NumHeaderLines',1);
data=XYZ(:,1:3); % select the three columns only
fmt=[repmat('%f,',1,numel(data)-1) '%f\n'];
fprintf(fid,fmt,data);
[m,n]=size(data);
X=XYZ(1:m,1);
Y=XYZ(1:m,2);
Z=XYZ(1:m,3);
end
fid=fclose(fid);
figure
pc = pointCloud(cat(3,X,Y,Z));
pcshow(pc.Location,'r')
title('Clustered Point Cloud')
xlim([-100 100]); % meters
ylim([-100 100]);
zlim([-5 5]);
hold on
figure
minDistance = 0.1;
[labels,numClusters] = pcsegdist(ptCloud,minDistance);
%Plot the labeled results. The points are grouped into two clusters.
pcshow(ptCloud.Location,labels)
colormap(hsv(numClusters))
%title('Point Cloud Clusters')
hold on
figure
pcshow(ptCloud)
xlim([-100 100]); % meters
ylim([-100 100]);
zlim([-5 5]);
title('Unclustered Point Cloud')
maxDistance = 0.3;
referenceVector = [0,0,1];
Thank you "Image Analyst" for answer half of my first question, I could not open his example due to privacy and Crome security warning, however, he/she was too busy and left my questions idle, so after almost 2 days waiting for the rest and inquiry, unfortunatly, I unaccepted his answer.

Sign in to comment.