[sharing + question] Find average color, ignoring black. (selective jit.3m)
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.)
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.)
this patch uses one of Wesley Smith’s xray externals (http://www.mat.ucsb.edu/~whsmith/xray.html):
----------begin_max5_patcher---------- 798.3oc0Xt0aaBCEG+4jOEd7vzlTZjM2YRUpSZOruCaSUNfSiaAajwjPaU+t OeARocIKWJIq6g.xWvmy4G9b9axiiG4Li2Ppb.eA7CvnQONdzHSW5NF01djS AtIMGWYllysT4zxUTVFekyD63r5BJKmHMS.01YIVltfxt4ZAIUZMPDZJbB.k DMMXBv0GpaE5MEB90yKDuV1sRts8Z6RdeIwtLNNST+V+PkBREgIwRJm0yXnX eq0Bz2fsWV+TzLSzvmc6EtgN59dZ7X8kIG.GlWVcSMsCCy4LICWX7RmuSxWR jzTb2nE7LyHdGHz7PIZb0RsXSf34tSnoclJ5CFShTS+MwRuDiYQdvcxR+igk o7hBkY6PkjzXLrZRh6.LN6hGHBNHkjmWsevdt3lY5QfqC78E2tHOCgQ1HNvd Kdq7F9248V.ZqUbCi2IP8FRflxYKIBIPxAyxwo2A9HX0BpjbpoJJLxDuwgCB U6yG2igOLxJ0C+G3QmSqhQ275B79gj8E.I98h+HucD9GZRrxuut.KEzlWlN2 iSnn+CJx4EaHyItHWOpjbrP4Mo.1FlClBXu.5ndKOy3oDwFiF31il1z31RYV wc2fsFMcbY81mLRAeIMivmpbG056rG6u2TPGNjkHmSykDAPq3bwRbdMwp67S 1IuFYqxiejEjdCVMxfSgDh62.1WIZwDz5FeJJLFBAWpRegfF8d7OexkrgVhE XDS8fACF37GPskFA99o5RGUz4xiPbwcW4gsabB+GHtDlLvhv7RvUpee3RvUp bP.bX4kULt6HdJomyNvhfCLvpRwrUBbIvGjt.K.1rPzF41WETb9gpb0VqOHp 2MW3YkYn9LyLCmbJ60e8pw208+RPVwqEocVqc4TG5dsgxHURJybN8dSR8og8 mzBZVFg0uFRFsBOKmX7R3FekNn9iJQ6ck+n9buyk+nN.6t8GUd06J97Jm9T5 OuZqwl8mj2WtyYjN6i2fNeadf6axN5H7GasQbYo5fZUsqowUTxI2xE5lgSLM oLaSSgeGAYIsa99ldvhT8eOPprVX0NZh0G1VYmmF+aPSaXKu -----------end_max5_patcher-----------
Hi, ZLP. I couldn’t see your patch but, anyway, see if it helps:
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.)
Forums > Jitter