I am in the process of writing an algorithmic piece where I take pictures, determine the most prevalent color in that picture, then store that as a number in an array. I would then call on these numbers to determine the triggering of samples.
Is there an object in Pure Data that can determine the most common color in an image? If so, how does it work?
Thanks for taking the time to read this, -Sebastian
Hi,
I think [pix_mean_color] is what you need.
Cheers.
01ivier
2011/9/11 Sebastian Valenzuela svalenzuelamusic@gmail.com
I am in the process of writing an algorithmic piece where I take pictures, determine the most prevalent color in that picture, then store that as a number in an array. I would then call on these numbers to determine the triggering of samples.
Is there an object in Pure Data that can determine the most common color in an image? If so, how does it work?
Thanks for taking the time to read this, -Sebastian
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
On Sun, 11 Sep 2011, Olivier B wrote:
I think [pix_mean_color] is what you need.
This only finds the average colour, which is usually not the same as the most prevalent colour, even though it is the best estimator.
The best estimator means that it's your best guess when someone asks you to predict pixels picked randomly in the image. It leads to least square error : (predicated - random)² is as low as it can be, on the long term.
In statistics, we learn about Average, Median and Mode, usually all 3 at once, as 3 basic approaches, three kinds of «middles» of the data. What Sebastian is looking for is more like Mode, which looks like the easiest of the 3, but is actually the hardest of the 3, especially when doing in multidimension spaces (such as red,green,blue) and on continuous scales (256 values per dimension is continuous enough for what I'm talking about).
There are several gotchas about peaks in statistical distributions.
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC
Yes... you're completely right Mathieu... I've made a bad link between his question and my pix_knowledge (maybe because it was 1h30 AM :-p )
Cheers.
01ivier
2011/9/11 Mathieu Bouchard matju@artengine.ca
On Sun, 11 Sep 2011, Olivier B wrote:
I think [pix_mean_color] is what you need.
This only finds the average colour, which is usually not the same as the most prevalent colour, even though it is the best estimator.
The best estimator means that it's your best guess when someone asks you to predict pixels picked randomly in the image. It leads to least square error : (predicated - random)² is as low as it can be, on the long term.
In statistics, we learn about Average, Median and Mode, usually all 3 at once, as 3 basic approaches, three kinds of «middles» of the data. What Sebastian is looking for is more like Mode, which looks like the easiest of the 3, but is actually the hardest of the 3, especially when doing in multidimension spaces (such as red,green,blue) and on continuous scales (256 values per dimension is continuous enough for what I'm talking about).
There are several gotchas about peaks in statistical distributions.
______________________________**______________________________** ___________ | Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC
On Sat, 2011-09-10 at 22:33 -0400, Mathieu Bouchard wrote:
On Sun, 11 Sep 2011, Olivier B wrote:
I think [pix_mean_color] is what you need.
This only finds the average colour, which is usually not the same as the most prevalent colour, even though it is the best estimator.
The best estimator means that it's your best guess when someone asks you to predict pixels picked randomly in the image. It leads to least square error : (predicated - random)² is as low as it can be, on the long term.
In statistics, we learn about Average, Median and Mode, usually all 3 at once, as 3 basic approaches, three kinds of «middles» of the data. What Sebastian is looking for is more like Mode, which looks like the easiest of the 3, but is actually the hardest of the 3, especially when doing in multidimension spaces (such as red,green,blue) and on continuous scales (256 values per dimension is continuous enough for what I'm talking about).
There are several gotchas about peaks in statistical distributions.
I wonder how one should go about this:
Let's assume an image consisting of the major parts of pixels that are at most -/+3 values (from 256) apart from each other in every plane (R, G, and B). So this pixels would be spread across 7x7x7 = 343 different colors, but would look still very similar to each other. Now, the rest (minor part) of the image consists of all the exact same color value, which is much different from the colors in the major part.
Am I right in thinking, that the Mode would detect the minor part (with all the exact same color values) as the most prevalent color, while the human eye most likely would see a mix of the previously described color variation as the most prevalent color? How would an algorithm work, that would take into account that all the pixels from the major part are very similar and thus would detect a mix of those as the most prevalent color?
Roman
On Mon, 12 Sep 2011, Roman Haefeli wrote:
Am I right in thinking, that the Mode would detect the minor part (with all the exact same color values) as the most prevalent color,
[...]
How would an algorithm work, that would take into account that all the pixels from the major part are very similar and thus would detect a mix of those as the most prevalent color?
It depends...
a strict Mode with smallest histogram bins (one per value) will find the minor part.
a strict Mode with big histogram bins (one for 16*16*16 values, for example) will find the major part only if their values don't overlap several bins, which is some kind of vote-splitting.
but if you do a Mode-like thing with smallest histogram bins AND a convolution by a window, you will get the major part in all circumstances, without «posterisation» artifacts.
however, if you don't want to make a 3-D histogram data structure taking 64 megs and a lot of CPU for applying a 3-D blur on that, you have to get trickier than that... does anyone have any ideas how to find a «blurry Mode» without using much RAM & CPU ?
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC
On Sat, 10 Sep 2011, Sebastian Valenzuela wrote:
I am in the process of writing an algorithmic piece where I take pictures, determine the most prevalent color in that picture, then store that as a number in an array. I would then call on these numbers to determine the triggering of samples. Is there an object in Pure Data that can determine the most common color in an image? If so, how does it work?
To be able to do this, you need to be defining how to clusterise your colours. For example, if you just classify them by their exact value, you might get a lot of a very specific shade, and select that, and miss the fact that there is another shade that looks very close to a lot of other shades in the picture, and so, by different criteria, it would be the most common.
What would match the perception of the human eye and most people's expectation, is something that picks the average of a bunch of very similar shades. That's not very obvious to do.
[cv/#KMeans] (from GridFlow's OpenCV wrappers) does something like that : it categorises the pixels in your image to make a palette (among multiple possible uses). Then you can use GridFlow's [#cluster_avg] to find the average colour of each palette item.
However, the palette items are not the best that can possibly be chosen, because it's impossible to guarantee it, and it's hard to do a good job in a short time. So sometimes it could pick too many palette items for the same kind of colours, and mislead you in finding the most used kind of colour.
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC