wood burning stoves 2.0*
The moose likes Java in General and the fly likes Algorithm: Brightness Difference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Algorithm: Brightness Difference" Watch "Algorithm: Brightness Difference" New topic
Author

Algorithm: Brightness Difference

Shyam Prasad Murarka
Ranch Hand

Joined: May 02, 2005
Posts: 209
Dear Readers,
I am using a program that allows the user to input two colors, one a Foreground color and the other a Background color. The program outputs whether the two colors have sufficient "color difference" and sufficient "brightness difference". If both conditions are fulfilled then these colors can be used as Foreground and Background colors.
I analyzed the outputs for different inputs and found the algorithm that the program used to calculate the "color difference".
I tried to do the same to find the algorithm used to calculate the "brightness difference". But in vain!
Does anybody know how to calculate the brightness difference?
I need this because I want to make a Java program that takes in a color input and outputs all the possible colors that can be used in combination with the input color.


With Best Regards,
Shyam Prasad Murarka
dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
well!!i dont know if i am exactly clear with your doubt but why dont you try to use methods from class Color..
below shown is the link for it...

http://java.sun.com/j2se/1.3/docs/api/java/awt/Color.html#getHSBColor(float,%20float,%20float)


here you refer to method

getHSBColor()

they have specified that the value of brightness is floating point value between 0 and 1.you try to use this kind of strategy in your program.
i hope it helps you.....


dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
one more link i would like to specify,here you read the topic

1)Threaded Solution

There are some algorithms from which you will get atleast some idea on your program.


so here is the link

http://www.ugcs.caltech.edu/~bird/cs3/ml9/
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41872
    
  63
Converting to a different color model (like HSB) seems like the easiest way to go, as dhwani mathur said. The Color.RGBtoHSB method can convert an RGB triplet to a HSB triplet.

While the brightness (B) parameter is what you'd be most interested in, also look at the saturation (S). It may be the combination of both that's relevant to your problem.


Ping & DNS - my free Android networking tools app
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

This is a bit advanced for beginners. Let's promote this topic to the intermediate forum.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Shyam Prasad Murarka
Ranch Hand

Joined: May 02, 2005
Posts: 209
Dear Readers,
Thank you for all your suggestions.
I tried the Color methods suggested above. It seems they are not what I needed.
I again tried analyzing the different outputs to come up with the algorithm that the program used.
I gave up at last and headed to the website of the program. After a bit of searching I was so RELIEVED to find the algorithm that they used displayed!
Here is the link, if anyone's interested.
And this is the more detailed version of the formula.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41872
    
  63
So what you actually needed was the luminance of a pixel, not its brightness. There is a color model called HLS which has that information. It's not supported by the java.awt.Color class, though, so it's a bit harder to use than HSB. HLS is accessible through the java.awt.color.ColorSpace class, though.
[ June 24, 2007: Message edited by: Ulf Dittmer ]
Shyam Prasad Murarka
Ranch Hand

Joined: May 02, 2005
Posts: 209
Dear Readers,
Oh! Thanks. I shall check it out.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Algorithm: Brightness Difference