MATLAB Answers

Averaging properties of a 3D point cloud on a 2D grid with sliding kernel

1 view (last 30 days)
Seb Biass
Seb Biass on 14 May 2018
Edited: Seb Biass on 14 May 2018
Hi all,
I have a 3D point cloud organised in a 3-colums format [x,y,z], with additional properties of each point from column 4 onwards. Note that the distance of all points is random. I am trying to implement a moving filter similar to blockproc in order to create a 2D matrix of size y,x that "flattens" the data along z and averages a given property of the point cloud in a volume. The volume should be a kernel of a fixed size along x and y, let's call them dx and dy within which values of any z will be taken. In addition, the volume should be able to slide, so for instance the moving steps (lets call them xStep and yStep) are not necessarily equal to dx and dy (though dx=dy and xStep=yStep).
So far, Matlab functions I found are:
blockproc: Has the ability to implement a sliding kernel but works on matrices
accumarray: Works on discrete points but no sliding kernel
Below is a cartoon of what I am trying to do conceptually. The function should capture the red points and apply a function (e.g. mean, stdev) to calculate the value of the red cell. Then move by xStep and re-apply the function.
Any idea of how I could achieve that? I've been stuck on that for a while. I wrote a function that indices the points at each iteration, but my datasets are rather large (>10^7 points) so this approach is very time consuming. This thread provides a MWE using accumarray, without the sliding kernel:
table = [ 20*rand(1000,1) 30*rand(1000,1) 40*rand(1000,1)]; % random data
x_partition = 0:2:20; % partition of x axis
y_partition = 0:5:30; % partition of y axis
L = size(table,1);
M = length(x_partition);
N = length(y_partition);
[~, ii] = max(repmat(table(:,1),1,M) <= repmat(x_partition,L,1),[],2);
[~, jj] = max(repmat(table(:,2),1,N) <= repmat(y_partition,L,1),[],2);
% Calculate the sum
result_sum = accumarray([ii jj], table(:,3), [M N], @sum, NaN);
Any input would be greatly appreciated!

  0 Comments

Sign in to comment.

Answers (0)