# How to graphicall​y/interact​ively select region of interest from 3D point cloud data

14 ビュー (過去 30 日間)
Qasim Nazir 2019 年 11 月 25 日
Edited: Qasim Nazir 2019 年 11 月 26 日
I am working with 3d point cloud data and interested in graphically selecting regions of interest from MATLAB figures. A possible scenario could be changing the view to one of the planes (e.g. XY plane) and drawing some contours or geometric shapes using cursor as shown below. Then selected datapoints should be stored in a workspace variable.
I found something similar for images (2d figures) but not sure how to that for 3d point cloud data.
Is something like this can be done in MATLAB?
Thanks.

#### 0 件のコメント

サインイン to comment.

### 採用された回答

Bjorn Gustavsson 2019 年 11 月 25 日
In newer versions of matlab there seems to be just such a feature, see: ROI.CUBOID
For older versions of matlab (I vaguely recall) there might be versions of ginput with extended 3-D capabilities on the file exchange: ginput-extensions
HTH

#### 3 件のコメント

Qasim Nazir 2019 年 11 月 26 日
Thanks for the help.
I was able to draw a roi.Cuboid and roi.Rectangle. Since I am considering complete z-range (-inf,inf) so I set the deafult view to XY-plane and found roi.Rectangle to be easier to use. So first step is done, I am able to get corrdinates for my roi (or geometrically define a roi).
Next question is how to select (filter) only those points from point cloud object that lie inside roi. There is a function findPointsInROI for point cloud object but it takes roi in a different way [xmin, xmax, ymin, ymax, zmin, zmax]. That will not work if my rectangle is rotated at some angle.
This is my code so far.
ax = pcshow(ptCloud,'VerticalAxisDir','Down');
ax.View = [0,-90]; % XY-plane default view
%% roi Selection (use one from following)
% roi.Cuboid
h = images.roi.Cuboid(ax,'Rotatable','z');
draw(h)
roi = [min(h.Vertices)', max(h.Vertices)'];
% roi.Rectangle
h = images.roi.Rectangle(ax,'Rotatable',true);
draw(h)
roi = [min(h.Vertices)', max(h.Vertices)';-inf,inf];
%% subset of ptCloud
selected_indices = findPointsInROI(ptCloud,roi);
sub_ptCloud = select(ptCloud,selected_indices);
Bjorn Gustavsson 2019 年 11 月 26 日
Well since you select all points based on their x and y coordinates it doesn't matter what other values (z and other possibly associated to the point), and you have a 2-D problem. For that you can let your selected edge-points define an arbitrary polygon and use the inpolygon. It would happily take arbitrary points and build a polygon (can be self-intersecting and have wholes inside and whatnot), so your rotated rectangular area should be "a walk in the park". Just check the help and documentation for inpolygon and you'll have your solution completed in minutes.
HTH
Qasim Nazir 2019 年 11 月 26 日
It worked out for me, thanks for your help. Final code is here.
ax = pcshow(ptCloud);
ax.View = [0,90];
%% draw roi
roi = images.roi.Polygon(ax) ;
draw(roi)
pause(3)
%% select points inside roi
x = ptCloud.Location(:,1);
y = ptCloud.Location(:,2);

サインイン to comment.