# How to select a region of interest (ROI) from 3-d point cloud data?

37 views (last 30 days)
Swati Jain on 27 Dec 2017
Commented: Swati Jain on 20 Aug 2021
Hi,
I want to select a rectangular region from my 3-d point cloud data (.asc file format). I applied two approaches to do that as follows:
1. I select 4 corner points of the rectangular ROI and then select all points lying between xmin, xmax, ymin, ymax and zmin, zmax. But somehow some other points (outside the ROI) are also satisfying this condition, therefore this approach is not working well.
pos = (y >= ymin) & (y <= ymax) & (x >= xmin) & (x <= xmax) & (z >= zmin) & (z <= zmax);
arr = [y(pos), x(pos) ,z(pos)];
2. By applying 'inpolygon' function but unfortunately it works only for 2-d points, Is there any other function which can be used?
xv=[-40.5 -34.32 -23.78 -29.11 -40.5];
yv=[9.362 13.35 -0.3085 -4.247 9.362];
zv=[409.9 406.7 412.1 415.1 409.9];
in=inpolygon(x,y,z, xv,yv,zv);
figure;
plot3(xv,yv,zv,'-r','linewidth',2);
hold on
plot3(x(in),y(in),z(in),'*b');
hold off
Getting an error:
Error using inpolygon
Too many input arguments.
Could you please suggest any other way to do that? I am not able to attach 3-d point cloud data due to size issue. Figure with ROI is attached.
Thanks,
Swati
##### 2 CommentsShowHide 1 older comment
Swati Jain on 21 Jun 2019
Hi, I still could not solve this issue. In my measurements I moslty have artiffact perpendicular to the axis of scanner and the code given below is working well if you have perpendicular situation.
pos = (y >= ymin) & (y <= ymax) & (x >= xmin) & (x <= xmax) & (z >= zmin) & (z <= zmax); %select coordinates of 4 corners and find min and max value of x, y and z
arr = [y(pos), x(pos) ,z(pos)];
However, I think we will have to select a cube around the ROI and then resolve it. Please let me know if you could resolve this issue.

Neil Guertin on 2 Jan 2018
Your first approach seems like the right way to do this. However it looks like your ROI is not orthogonal to the axes, and therefore the condition may be more complicated than just providing bounds on x y and z individually.
It also appears that your ROI is a 2d rectangle inside a 3d space. Does this mean you are only interested in points that fall exactly on the rectangle's plane? On it within some tolerance? These are things that could be easily accounted for with this logical indexing approach but would not be built in to other tools like inpolygon or roipoly.
Swati Jain on 15 Jan 2018
Thanks for your response. Actually ROI should be a cube but I am unable show it in that form. I mean some thickness is also there. About tolerance, I am mostly interested in the transition from lower to higher region and rectangular shape. I can not account this with logical indexing as the data is not sequential but random. We don't know which point is situated where.
Thanks, Swati

MoHa on 3 Aug 2021
Hello swati,
i also have the same problem. would be nice if you share your solution.
Kind regards
Reza
Swati Jain on 20 Aug 2021
Hi Reza,
My approach is correct and the only thing is that ROI should orthogonal to the axes.
Hope this helps.