Measuring percentage of color in matrix (still image)
I know this must be simple, but I'm having a hard time figuring out the best way to have my patch simply analyze a matrix (in my case, a graphic still image), measure how many pixels/percentage of the image is a particular color (given a particular ARGB range, as with jit.findbounds), and spit it out. It almost seems as if I need to simply find some way to automate a whole matrix full of bangs to suckah and then manually record the output, but I'm thinking there must be some easier way. is there?
check out jit.3m and jit.histogram
Thanks, Rob. They don't do what I need, but I'm getting closer. Using Suckah, I created a patch that allows me to see the values in an RGBA list of the (very limited number of) colors in the image. By using jit.iter, I can scan through the image really quickly and send all of the RGB values quickly (alpha value is always 1.0 in the image I'm using).
Now all I need to figure out is how to use list processing to compare these values with the values I'm looking for, then send it all to a counter to let me know how many of each value there are.
Is there something like SEL for a list, ideally with a margin of error, ie range, that I could send all the jit.iter lists through?
This is for a still image, not video, so it doesn't matter if it's fairly slow. I want to send the "number of pixels for each color" out to control audio levels, if that makes a difference.
Here's what I've got so far:
You need to think in terms of colour space, and how far a colour is from another one in that space. So it becomes a geometrical problem. There are many colour spaces: RGB, HSV, Lab, CMYK etc. The rgb space is only really useful for displaying pixels, not for any analysis. HSV (or HSB, hue, saturation, brightness) is a somewhat more appropriate. SO think of a colour being a point in the space defined by the 3 axes, and colour-similarity can be measured by how close two colours are from each other; if the distance is zero, then they are the same!
So you can measure distance in a number of ways, but the most common is euclidean, which is the square-root of the sum of the squares of the differences between the two colours along each of the axes. this is easily done using expr boxes:
So you need to convert the rgb to something more appropriate, then test for distance within a margin of error... you may need to put your reference colours in a coll and iterate through them for each colour you're testing...
Thanks! This patch is really useful.
I guess the next thing to figure out is how to pass the list down if it does NOT meet the margin of error... is there something like SEL for a list?
I don't really know what you're asking, but there is something like a [sel] for a list in the zl suite of objects, ie, [zl compare]->[sel 1]
Hey I know this is like an old post, but if someone somehow should come across this post, I just wanted to share my take on figuring out the percentage of color in a picture or matrix. I don't know if this is the simplest way, but at least I didn't have to get knee deep in outdated API's or K means algorithms.