How to find complementary colour for pixel

J

Johny

I use PIL to write some text to a picture.The text must be seen wery
clearly.
I write the text to different pictures but to the same position. As
pictures maybe different, colour, in the position where I write the
text, is also different.
Is there a way how to set the font colour so that it will be seen very
clearly in the picture?
For example, if the picture is bright ( for example yellow), the font
colour should be dark( e.g. black) and vice versa.
Is there a routine in PIL available that calculates complementary
colour for RGB pixel format?
Can anyone help?
Thanks
L.
 
B

Bjoern Schliessmann

Johny said:
As pictures maybe different, colour, in the position where I
write the text, is also different.
Is there a way how to set the font colour so that it will be seen
very clearly in the picture?
For example, if the picture is bright ( for example yellow), the
font colour should be dark( e.g. black) and vice versa.
Is there a routine in PIL available that calculates complementary
colour for RGB pixel format?

IMHO, this looks weird, especially in complex images. A better
solution is to draw a background box behind the text that has the
image colors, butt low contrast (or saturation, or whatever).
Can anyone help?

....

Regards,


Björn
 
J

James Stroud

Johny said:
I use PIL to write some text to a picture.The text must be seen wery
clearly.
I write the text to different pictures but to the same position. As
pictures maybe different, colour, in the position where I write the
text, is also different.
Is there a way how to set the font colour so that it will be seen very
clearly in the picture?
For example, if the picture is bright ( for example yellow), the font
colour should be dark( e.g. black) and vice versa.
Is there a routine in PIL available that calculates complementary
colour for RGB pixel format?
Can anyone help?
Thanks
L.

Don't you just xor with black?
 
S

Steven D'Aprano

Don't you just xor with black?

I shouldn't think so... I always forget if black is all ones or all
zeroes, so I checked here: http://www.pitt.edu/~nisg/cis/web/cgi/rgb.html
False

Maybe you meant xor with white?

But even so, I gather that the Original Poster is asking for something
slightly different -- despite his mention of complimentary colours. (Or
maybe I'm just reading too much into it?)

I think he's just looking for one colour which has high contrast over a
bunch of pixels in an image. I don't think that can be done, in general:
it seems to me he's assuming that all the pixels in the area he wants
to overlay text on are "nearly" the same colour.

I think that a better solution is to draw a box around the area you
want to write text into. The box should have a contrasting frame:
say, a thin white border followed by a thin black border just inside it:
either the white or the black will contrast with the background, no matter
what colour(s) the background is, since no area can be both black and
white in the same place. Then fill the frame with white, and draw black
text inside it. Nice high contrast.

That is probably the most readable method of placing text over an image.
 
L

Laurent Pointal

Steven D'Aprano a écrit :
I shouldn't think so... I always forget if black is all ones or all
zeroes, so I checked here: http://www.pitt.edu/~nisg/cis/web/cgi/rgb.html

For this I use the mnemotechnics idea of "chromatic coil" [*], when
there are *all* colors turning it appear to be *white*. And *no* color
is then *black*.



[*] Babelfish translation for french "roue chromatique"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top