I have a matrix M with size m x 3 , where m is the total number of points (thousands of points). The three columns correspond to x, y and value. I want to map the values into an image efficiently. This task is very easy, but I need to speed up the process. I came up with the following two approaches:
First approach (Testing on 3600 points, I got a run time of 0.07 seconds.)
a = M(:,2);
b = M(:,1);
c = M(:,3);
img= accumarray ([a(:),b(:)],c(:));
img(1000,1) = 0;
img(1,1000) = 0;
Second approach (Testing on 3600 points, I got a run time of 0.04 seconds.)
img = zeros(1000,1000);
for i = 1 : size(M,1)
img(M(i,2),M(i,1)) = M(i,3);
parfor is not an option here in the second approach.
Does anyone know how to make this process faster?
Please note that I excute this code 50 times per frame obtained from a camera, resulting with a 2 second run time per frame.