2

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?

4

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:

lenna

a palette.png:

palette

or palette.txt:

#D2615E
#B24953
#DE8D75
#5D133B
#65214C
#D36F6D
#EECAAA
#DCA295
#C78E79
#8F283D
#CEB3B6
#99364B
#A36A90
#A95D6B
#7B4886
#75416E

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).

| improve this answer | |
  • 1
    Wow what an amazingly complete answer, thank you. – Supuhstar Dec 16 '14 at 3:02
1

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

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

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.

| improve this answer | |

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.