Processing Pixels (quickly and efficiently)
in
Programming Questions
•
2 months ago
Apologies up front for the probably silly question - I'm still very new to processing.
I am processing points moving around a screen (actually of height 1200 width 1000, so 1.2 million pixels in total on the screen).
The points are synonymous with vehicles moving around an area. So a vehicle which moves from point A to B is displayed on the screen by a (blue) point moving from pixel A to B.
I wanted to be able to abstract from my millions of vehicles (or blue dots on the screen) to pull out where is 'busiest' i.e. which pixels are traversed most often by a vehicle.
To do this I created an array (displayarray), and started to loop through each painted pixel. If a pixel was painted blue in a time bin then I added 1 to the count for that box, if it was not painted (i.e. not occupied by a vehicle) then I decayed the count. So pixels which were always blue would get a high count.
Then I wanted to update the pixels on the screen to only draw the pixels with high counts (the busy ones).
The problem is...it takes FOREVER to run. I'd really appreciate any guidance that can be offered. Im sure I must be over complicating things or missing some efficiency trick?
Thanks in advance!
for (int i = 0; i < pixels.length; i++) {
int b = int(blue(pixels[i])); //is this pixel currently blue?
if (b >= 0) {b = 1;} else {b = -1;} //if yes, then add 1 to the count, otherwise, decay it
displayarray [i] = displayarray [i] + b; //give the pixel the value it had in the last iteration, plus its updated amount
//now repaint everything which has a high count only
if (displayarray [i] >= display_threshold) {pixels[i] = color(0,0,255);}
updatePixels();
}
//then loop through to the next time bin and continue in the same way.
1