Store a group of points (given x, y, and value) into image efficiently
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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);
end
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.
2 Commenti
Guillaume
il 7 Ott 2019
As I said, it's unlikely you'll find anything faster. Your loop code and my answer do the bare minimum: memory allocation (with zeros) then simple memory copy using an offset. At this point, the only thing that could make it faster is if the data to be copied is ordered with regards to the destination.
Risposta accettata
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!