• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Color comparison
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Color comparison


  • Subject: Re: Color comparison
  • From: Jason Harris <email@hidden>
  • Date: Tue, 04 Jun 2002 11:48:52 -0700

You could also use the Euclidean distance in whatever color space your color
lives in. For RGB, it's
distance = sqrt( pow(r1-r2, 2.0) + pow(g1-g2, 2.0) + pow(b1-b2, 2.0) );
"distance" is a number in the same units as r,g, and b that describes how
"close" the the two colors are.

Jason Harris


Marcel Weiher Tried to Tell Me:

> On Tuesday, June 4, 2002, at 12:08 Uhr, David Sinclair wrote:
>
>>
>> Alternatively, is there any way of avoiding the difference in values. I
>> doubt this one is feasible, as it looks like a rounding difference --
>> e.g. 0.0588235 vs 0.0581305.
>
> You generally can't use equality to compare float/double values, because
> of rounding differences. So you typically need some tolerances.
>
> Here are two handy functions I use that compare to a tolerance specified
> as a percentage of the values in question.
>
>
>
> static BOOL valuesWithinPercentRelativeTo( float v1, float v2,float
> baseVal, int percent )
> {
> if ( v1 == 0 && v2 ==0 ) {
> return YES;
> } else {
> float diff = fabs( v2 - v1 );
> float percentOfV1 = fabs(percent * baseVal / 100.0);
> return diff <= percentOfV1;
> }
> }
>
> static BOOL valuesWithinPercent( float v1, float v2, int percent )
> {
> return valuesWithinPercentRelativeTo( v1, v2, v1, percent );
> }
>
>
>
> --
> Marcel Weiher Metaobject Software Technologies
> email@hidden www.metaobject.com
> Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
> _______________________________________________
> cocoa-dev mailing list | email@hidden
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Color comparison
      • From: Marcel Weiher <email@hidden>
References: 
 >Re: Color comparison (From: Marcel Weiher <email@hidden>)

  • Prev by Date: Recursive Calls increase the memory
  • Next by Date: Re: NSScroller drawing disabled. Why?
  • Previous by thread: Re: Color comparison
  • Next by thread: Re: Color comparison
  • Index(es):
    • Date
    • Thread