As part of my project to add computer vision stuff to pygame, I'd like to write a function or functions that do the following.
For vision purposes, it would be very useful to have thresholding with both upper and lower boundaries, returning both the number of pixels within the threshold and the centroid of those pixels. This is a trivial addition to the existing transform.threshold() function, but is it acceptable to modify the input options and the output of an existing function? Would it break compatibility with existing pygame games? Would it make sense to have a second function so similar to an existing one? The other function, which is also similar (and could even just be an option in thresholding), is thresholding with connected component detection. This would involve supplying an upper and lower threshold, a Surface, and optionally a mask. The function would find the largest blob of pixels in the Surface within the threshold, make a mask of those pixels if desired, and return the centroid and number of pixels in the blob. It could also be useful to have multiple connected component detection, for "multi-touch" without having to use different colored objects (or if you are using IR LEDs like the Wii does), but I'm not sure how to handle that in a single pass of the array. Actually, I'm not really sure how I'm going to handle both detection and creating a mask in a single pass either. It may be necessary to store the starting pixel, ending pixel, and size of each connected component on the first pass, keeping track of which was the largest yet, and then have a shorter second pass to create the mask that only starts at the starting pixel and ends at the ending pixel. Any comments, reality checks, questions, or suggestions would be greatly appreciated. Nirav