[sharing + question] Find average color, ignoring black. (selective jit.3m)

    Nov 22 2013 | 6:58 pm
    Attached is my inelegant solution to a problem I often face: How to calculate the average color of all pixels that aren't black. (How do I make jit.3m ignore black pixels?)
    I want to detect the average color of certain objects. I performed background subtraction on a camera feed, leaving me with objects against a black background. After converting to HSL colorspace I wanted to get the average hue of the non-black pixels. (This isn't possible with jit.3m since it includes the black pixels in the average, watering-down the data.)
    My Solution:
    In the attached patch I iterate through the matrix, testing to see which pixels meet minimum saturation and luma conditions. If they pass the test, those pixels are added to a new 1D matrix which can be analyzed with jit.3m. It works perfectly but it's slow as molasses.
    Question: Can somebody share a smarter approach?. (maybe js or gen?)
    Patch and small sample video are attached. No camera or background-subtraction required. (The forum software wouldn't let me include my copy-compressed patch in the post, sorry.)

    • Nov 22 2013 | 8:16 pm
      this patch uses one of Wesley Smith's xray externals (http://www.mat.ucsb.edu/~whsmith/xray.html):
    • Nov 23 2013 | 7:41 pm
      Hi, ZLP. I couldn't see your patch but, anyway, see if it helps:
    • Nov 24 2013 | 6:14 pm
      Pedro - I actually saw your patch in the other thread. Great idea. So simple!
      I think that finding mean hue in HSL space isn't as simple though, because I need to analyze the luma plane to find the black pixels, but apply those exceptions to the mean of the hue plane. (This is because black pixels don't necessarily have a hue of zero.)
      Still looking...