473,378 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How to find complementary colour for pixel

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.

Apr 26 '07 #1
4 3703
Johny wrote:
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

--
BOFH excuse #405:

Sysadmins unavailable because they are in a meeting talking about
why they are unavailable so much.

Apr 26 '07 #2
Johny wrote:
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?
Apr 27 '07 #3
On Thu, 26 Apr 2007 21:17:42 -0700, James Stroud wrote:
Johny wrote:
> 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?
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
>>black = 0x000000 # RGB colours
white = 0xffffff
black^black == white
False
>>white^black == black
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.
--
Steven D'Aprano

Apr 27 '07 #4
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"
Apr 27 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: Dom | last post by:
can someone please help me display text in the console cout << "Testing"; in a different colour to the default one
4
by: Dj Frenzy | last post by:
Hi, I know how to use javascript to change a background image to another background image, and how to change a background colour to another background colour. Is there a way to change an image to a...
3
by: Mark Ingram | last post by:
Hi, ive got an imagine in a PictureBox, and would like to get the colour of the pixel when the mouse is over the control. From what ive (briefly) seen, there is no way to do this directly in C# and...
2
by: R. MacDonald | last post by:
Hello, Group, If drawing on a control, it would be desirable to select a colour that significantly differs from the control's background colour. Is there a standard (or preferred) way to...
10
by: Pulzar | last post by:
Hi there, I want to show a simple image on a web page, and allow the viewer to select and change one of the colours used in the image, and immediately preview the result. I'd like to keep the...
3
by: Johny | last post by:
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...
5
by: beertje | last post by:
This has me a bit stumped... I'm trying to extract pictures from a file. So far I'm successfully retrieved the header and what I think is the colour for each pixel. Here's the description: ...
2
by: kuratkull | last post by:
Hello, I haven't asked If I wasn't really confused :) OK, so I am just beginning SDL programming in C, and I was running fine, until I tried getting a pixel colour. Basically, I am trying to...
1
by: ofiras | last post by:
In bitmap, how can I find the nearest pixel (pixel 1) to a specific pixel (pixel 2) that has different color from pixel 2? Or how can I find a pixel in a specific distance from pixel 2 (like a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.