Wierd one - web color comparison

Hi Experts,

         Ive parsed the style sheet of a web page document and now im examining the document to identify visual segnmentation e.g. two sections with distinctly different background colors. What i need to know is if its possiable to compare two strings that represent color in style sheets i.e. background-color:#333333;

I need a method that gives a quantitive value to show how much the colors differ.

Any help welcomed.

Thanks, Chris.
icb01co1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
not sure i understand your problem.
Why don't you just parse the value as an integer
0
JakobACommented:
Yes and no.  The colorcodes used in RGB colors are not linear with respect to the percieved colors.
So you can compare, but the comparison is not worth much.

the color #334455 should be read as 3 seperate numbers
  int redComponent    = Integer.parseInt( "#334455".substring(1,3), 16 );
  int greenComponent = Integer.parseInt( "#334455".substring(3,5), 16 );
  int blueComponent   = Integer.parseInt( "#334455".substring(5), 16 );

to compare you then calculate the difference individually for each color component:
    int redDifference = Math.abs( redComponent_nr1 - redComponent_nr2 );
    int greenDifference = Math.abs( greenComponent_nr1 - greenComponent_nr2 );
    int blueDifference = Math.abs( blueComponent_nr1 - blueComponent_nr2 );
    int totalDifference = redDifference +greenDifference +blueDifference;

But remember that this difference calculation will not give you quite the differences you intuitively expect. I just hope it may be good enough for your purposes.

regards JakobA
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
icb01co1Author Commented:
Pure genius, thankyou very much kind sir.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.