WYSIWYG

http://kufli.blogspot.com
http://github.com/karthik20522

Thursday, December 6, 2012

Dominant Background color extraction in Images

Following is a continuation to my github project at https://github.com/karthik20522/DominantBackgroundColor

The problem of background color extraction hit me when I was trying to dynamically set background color based on dominant color of the image which usually is background color. Part of my solution was to average out the colors and perform a histogram equalization to extract a dominant color.

Since there are 255 x 255 x 255 possible combinations of colors it would more useful to reduce the result to more limited color space. For example if you want to provide filtering or sorting functionality of images with particular color it would be more user friendly to provide a limited/controlled set of color options instead of displaying 100's or 1000's of colors for the user to pick! In this project I used monochrome values of rainbow colors as my closest matching color subset for matching purposes.

Following is some examples of how the code performed:
Result Result Result Result


There are two main functions in the code that can be utilized:

1. To Extract the most dominant color in the image:
2. Convert the dominantHTMLColor to a smaller subset result
Examples of the above Subset/Closest match code:
Actual Actual Actual Actual
Subset Subset Subset Subset

For the most part the results are very close to the original dominant color. The whole idea was to match the resulting dominant color to one of the following rainbow colors:



But what if you want the code to return a list of top 5 colors. Well, you can modify the code as per your requirement by making this simple change to the linq query (which is currently set to pick the top color):

Labels: , ,