I am working towards having a method for scanning and averaging each point with the neighbouring points (in a specific radius defined by the user) for a point cloud. I have been told this is referred to as kernel filtering but I might be wrong on that, so apologies in advance. I have been testing this algorithm on the kettle point cloud provided by MATLAB.
I had the idea to try to grab the indices of the neighbouring points for a single point in a specificed radius (which will be tweaked by the user once created into a function). Then to compare this set of indices to the Nx3 matrix (point cloud matrix) to get the neighbours of the point, which are all (median) averaged to get a new point. I have came across a few problems while working on this algorithm.
PC = pointCloud(xyzPoints);
r = 0.5;
for i= min(PC.XLimits) : max(PC.XLimits)
for j = min(PC.YLimits) : max(PC.YLimits)
for k = min(PC.ZLimits) : max(PC.ZLimits)
[indices,dists] = findNeighborsInRadius(PC,[i,j,k],r)
pts = PC.Location(indices,:,:)
ptsX(n,1) = median(pts(:,1));
ptsY(n,1) = median(pts(:,2));
ptsZ(n,1) = median(pts(:,3));
n = n+1;
AveragedPC = [ptsX,ptsY,ptsZ];
This is the properties of the kettle point cloud (xyzPoints)
This method will only works for a certain amount of points because of how the limits for i,j,k are set up, they skip over more precise points. So instead of having ~5000 points, the algorithm collects 140 (as seen by the variable AveragedPC).
Also I have a problem with the AveragedPC showing a lot of NaN values. This happens when there are not any indices to collect near the specified point. I am unsure of how to implement a method to skip to the next point if no indices are collectable within the radius of the point. The main problem I would love some help on though is the method of scanning, as there isn't much point trying to filter out NaN points when basically all the points are being removing for the point cloud.
Either way, thank you for taking the time read this and any advice on scanning all the points in the point cloud would be appreciated.