I'm looking for something like what Windows 8+ uses for "Automatic" coloring, or the new YouTube Android app uses for its userpage nav bars, where the app automatically looks at the picture and return a palette of main and compliment colors.

Does any such program or API exist that is also open-source?


I am not aware what Windows 8 or new YouTube app does, since I do not use either, but if you want to get an N-colours palette sorted by frequency, i. e. you seeking how to get from image.png:


a palette.png:


or palette.txt:


then it’s quite a basic task for any image processing tool.

That how it could be done with ImageMagick (plus a bit of GNU Bash, Coreutils and AWK):

$ convert "image.png" -colors 16 -depth 8 -format '%c' histogram:info:- \
    | sort --reverse --numeric-sort \
    | gawk 'match ($0, /^ *[0-9]+: \([^)]+\) (#[0-9A-F]+) .+$/, a) { print a[1] }' \
    | tee "palette.txt" \
    | while read colour; do convert -size 20x20 "xc:$colour" +depth miff:-; done \
    | montage - -geometry +0+0 "palette.png"

That’s an example, of course; you have not to exec convert and monage via system(3) call from your program – interfaces for ImageMagick are available for all popular languages: C, C++, Perl, Python, Ruby, Java, etc. And it is a free/libre software (covered by Apache v2 license, to be precise).

  • 1
    Wow what an amazingly complete answer, thank you. – Ben Leggiero Dec 16 '14 at 3:02

There are a lot - probably one of the easiest is ImageMagik convert, e.g.:

  convert rose: \
          -define histogram:unique-colors=false \

Which gives, in this case for the rose image: enter image description here

You can do similar things in a number of FOSS image processing programs such as GIMP, G'IMIC, Darktable...

You can also do this sort of things with python tools, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.