algorithm - Fast way of getting the dominant color of an image -
i have question how dominant color of image (a photo). thought of algorithm: loop through pixels , color, either red, green, yellow, orange, blue, magenta, cyan, white, grey or black (with margin of course) , it's darkness (light, dark or normal) , afterwards check colors occurred most. think slow , not precise. there better way?
if matters, it's uiimage taken iphone or ipod touch camera @ 5 mpx. reason has fast showing progress indicator doesn't make sense app people bad sight, or no sight @ all. because it's mobile device, may not take memory (at 50 mb).
your general approach should work, i'd highlight details.
instead of given list of colors, generate number of color "bins" in color spectrum count pixels. here's question has algorithms that: generating spectrum color palettes make number of bins configurable, can experiment results want.
next, each pixel you're considering, need find "nearest" color bin increment. you'll need define "nearest"; see article on "color difference": http://en.wikipedia.org/wiki/color_difference
for performance, don't need @ every pixel. since image elements cover large areas (e.g., sky, grass, etc.), can result want sampling few pixels. i'd guess results sampling every 10th pixel, or every 100th. can experiment factor well.
[editor's note: paragraph below edited accommodate mike fairhurst's comment.]
averaging pixels can done, in demo:jsfiddle.net/must8/
Comments
Post a Comment