Info
Version: | 1.1.0 |
Author(s): | Pieroxy |
Last Update: | Friday, June 5, 2015 |
.NET Fiddle: | Create the first Fiddle |
Project Url: | http://pieroxy.net/blog/pages/color-finder/index.html |
NuGet Url: | https://www.nuget.org/packages/ColorFinder |
Install
Install-Package ColorFinder
dotnet add package ColorFinder
paket add ColorFinder
ColorFinder Download (Unzip the "nupkg" after downloading)
The value is then the number of pixels of the same color encountered. However, this gives poor results so here are the improvements I wrote:
I treat at most 5000 pixels so if the image is bigger I start undersampling. This is an order of magnitude, not a certain rule.
To avoid noise due to flat areas (text, borders, ...) I start by right shifting all the RGB values by 6. So all the values are now between 0 and 3, allowing to encompass large areas of almost-the-same color.
Then I perform another pass of the same algorithm (with a shift of 4) on all the pixels falling in the previous winning color group. And so on until I reach zero.
When trying to find the group that has the most pixels, I use a callback to weight the score. This allows customization and tell the algorithm you wand a rather dark color, you wan to exclude black, you want only highly saturated color excluding the greys or anything else you might think of.