TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Using imagemagick, awk and kmeans to find dominant colors in images

93 pointsby rubikscubeover 9 years ago

8 comments

neyaover 9 years ago
This is much easier using the LAB color space. I wrote an algorithm using the LAB color space several years ago to achieve something similar:<p><a href="http:&#x2F;&#x2F;i.imgur.com&#x2F;M6Oo6dp.jpg" rel="nofollow">http:&#x2F;&#x2F;i.imgur.com&#x2F;M6Oo6dp.jpg</a><p>Will open source it soon, perhaps.
bootloadover 9 years ago
There is an improvement that can be made here. There is no attempt to find the brightest colour. If you look at the dark image, the brightest colours (red) stand out over and above the dark colours. Using this knowledge is an illustration technique. Notice how the red stands out on one image, a small blue line on the other?<p>This particular algorythm and others that I&#x27;ve seen don&#x27;t take this into account. Depending on the image, you could also take into account the lightness and darkness to find the dominant colour however small amounts in the image.
评论 #10313060 未加载
评论 #10310133 未加载
andrewgleaveover 9 years ago
I wrote a small Go tool[1] that extracts a color palette from an image using either median or mean quantizer.<p>The quantizer code[2] is well documented and worth reading if you&#x27;re looking at doing this in Go.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;andrewgleave&#x2F;color-extract" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;andrewgleave&#x2F;color-extract</a> [2] <a href="https:&#x2F;&#x2F;github.com&#x2F;soniakeys&#x2F;quant" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;soniakeys&#x2F;quant</a>
w00kieover 9 years ago
I was expecting a step by step decomposition of the process. I&#x27;m a bit disappointed.
dxbydtover 9 years ago
To find k dominant colors using kmeans and then replace all the colors with their closest dominant color, try this - <a href="http:&#x2F;&#x2F;github.com&#x2F;krishnanraman&#x2F;colorquantization" rel="nofollow">http:&#x2F;&#x2F;github.com&#x2F;krishnanraman&#x2F;colorquantization</a><p>50 lines of Scala with lots of comments. I threw in some example images as well.
bruteover 9 years ago
Does the while (1) {...} loop always terminate? I am not entirely sure about it and would like to hear some opinions. What if the first guess is already the best possible solution? Could there be any pictures that cause trouble? I.e. ones that consist of 4 (equally spaced) colors only.
madsravnover 9 years ago
I read the same article as the guy and was also discouraged by using PIL. Python 2 vs Python 3 just makes life hard for people not used to Python. Maybe someone should do something about that.<p>I just went ahead and implemented the code in C++ instead.
评论 #10310035 未加载
jlhonoraover 9 years ago
Couldn&#x27;t this be achieved with imagemagick&#x27;s builtin blur + histogram?
评论 #10311616 未加载
评论 #10316670 未加载