Clear Filters
Clear Filters

scale a point cloud (enlarge or reduce)

22 views (last 30 days)
Alberto Acri
Alberto Acri on 29 Nov 2022
Answered: Jeffrey Clark on 30 Nov 2022
Hi. Is there a method to scale a point cloud (enlarge or reduce)?
I have Rowsx3 coordinates in a .txt file that I turned into a point cloud with the pointCloud command. I want at this point to scale the point cloud so that it has the same size as another point cloud (I have the same object, but different point cloud) possibly using a parameter. Is this possible?

Answers (1)

Jeffrey Clark
Jeffrey Clark on 30 Nov 2022
@Alberto Acri, I don't have the toolbox you do but you should be able to expand Rowsx3 similar to this (red are added):
% Create an example Rowsx3
[x,y,z] = sphere(60);
i = randperm(length(x(:)));
Rowsx3 = [x(i)' y(i)' z(i)'];
% Find nearest neighbors
d2d = (Rowsx3(:,1)-Rowsx3(:,1)').^2+(Rowsx3(:,2)-Rowsx3(:,2)').^2+(Rowsx3(:,3)-Rowsx3(:,3)').^2;
d2d(d2d(:)==0) = nan;
[d2dm,d2di] = min(d2d);
% If want 75x75 = 5625 instead of 3721 (61x61)
k = (75^2-length(Rowsx3));
% Choose mean of random nearest neighbors for cloud growth
ei = randperm(length(Rowsx3),k);
Rowsx3e(:,3) = mean([Rowsx3(d2di(ei),3) Rowsx3(ei,3)],2);
Rowsx3e(:,2) = mean([Rowsx3(d2di(ei),2) Rowsx3(ei,2)],2);
Rowsx3e(:,1) = mean([Rowsx3(d2di(ei),1) Rowsx3(ei,1)],2);
% Plot original as blue and extension as red (red are added)
figure
plot3(Rowsx3(:,1),Rowsx3(:,2),Rowsx3(:,3),'b.',Rowsx3e(:,1),Rowsx3e(:,2),Rowsx3e(:,3),'r.')
axis square; axis equal
As for reducing Rowsx3 just removing some of the nearest neighbors should work as well (red are removed):
% . . .
% If want 50x50 = 2500 instead of 3721 (61x61)
k = (50^2-length(Rowsx3));
% Choose random nearest neighbors for cloud reduction
ei = randperm(length(Rowsx3),-k);
Rowsx3r = Rowsx3;
Rowsx3r(ei,:) = [];
% Plot original as red and remaining as blue (red are removed)
figure
plot3(Rowsx3(:,1),Rowsx3(:,2),Rowsx3(:,3),'r.',Rowsx3r(:,1),Rowsx3r(:,2),Rowsx3r(:,3),'b.')
axis square; axis equal

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!