class TrackModule { private float th = 80; //brightness 0-255 private int hh = 80; //percent 0-100 TrackModule() { } float processBitmap(PImage bm) { int index; int hits; int successive_hits = bm.width * (hh / 100); /* this is a sort of filter. we run through the pixels one horizontal line at the time if we find a pixel with a brightness below the threshold (th) we add a hit. So if 80 percent of a line is dark enought to trigger the filter we count that as a dark line spotted and we retun the y value were it was spotted. */ for(int y = 0; y < bm.height; y++) { hits = 0; index = y * bm.width; for(int x = 0; x < bm.width; x++) { color c = bm.pixels[index + x]; if( brightness(c) < th) { hits++; if(hits > successive_hits) { return y; } } } } return 0.0; } }