Page 1 of 1

[SOLVED] Getting complementary color from a given color

Posted: 2014-06-07T03:40:22-07:00
by cubancigar11
Hi!

I am trying to find the two colors from an image: the dominant one, and its complementary. From viewtopic.php?f=1&t=12878, I am able to get the dominant color using following command:

Code: Select all

convert img.png -colors 16 -depth 8 -format "%c" histogram:info:|sort -rn|head -n 1|grep -oe '#[^\s]*'
But I don't want to process the same image again to get the complementary. Is it possible?

PS: I am not looking for exact values for colors.

Re: Getting complementary color from a given color

Posted: 2014-06-07T04:46:22-07:00
by snibgo
The complement of a colour is (usually) the same lightness and saturation, with the hue rotated by 180 degrees, or 50%. We can do this with "-modulate":

Code: Select all

convert xc:red -modulate 100,100,0 txt:
For "red", use any color you like, eg

Code: Select all

convert xc:srgb(10%,20%,30%) -modulate 100,100,0 txt:

Re: Getting complementary color from a given color

Posted: 2014-06-07T09:10:03-07:00
by cubancigar11
Thanks. I am assuming there is no way to print it in #rrggbb format instead of #rrrrggggbbbb. But that is not a problem. Thanks again.

Re: [SOLVED] Getting complementary color from a given color

Posted: 2014-06-07T09:41:03-07:00
by fmw42
add -depth 8 to snibgo's solution.

convert xc:"srgb(10%,20%,30%)" -modulate 100,100,0 -depth 8 txt:

Re: [SOLVED] Getting complementary color from a given color

Posted: 2014-06-07T12:17:46-07:00
by cubancigar11
Thanks! That does it!

Code: Select all

% convert xc:'#004d09' -modulate 100,100,0 -depth 8 txt:
# ImageMagick pixel enumeration: 1,1,255,srgb
0,0: ( 77,  0, 68)  #4D0044  srgb(77,0,68)