hutelihut
asked on
How to compare colors
How do I make a function that compares two colors and return TRUE if the two colors are the same?
There has to be some kind of "tolerance-variabel", for example:
When Tolerance is 0 the function returns true if the two colors are exactly the same
When Tolerance is 10 the function returns true if the two colors are mostly the same
When Tolerance is 50 the function returns true if the two colors are slightly the same
and so on...
The function could be something like:
function SameColor(Color1,Color2:tC olor; Tolerance:Word):boolean;
begin
SameColor:=abs(GetRValue(C olor1)-Get RValue(Col or2))+
abs(GetGValue(Color1)-GetG Value(Colo r2))+
abs(GetBValue(Color1)-GetB Value(Colo r2))<=Tole rance;
end;
...but this does not work very well.
How do I make this function in a better way?
There has to be some kind of "tolerance-variabel", for example:
When Tolerance is 0 the function returns true if the two colors are exactly the same
When Tolerance is 10 the function returns true if the two colors are mostly the same
When Tolerance is 50 the function returns true if the two colors are slightly the same
and so on...
The function could be something like:
function SameColor(Color1,Color2:tC
begin
SameColor:=abs(GetRValue(C
abs(GetGValue(Color1)-GetG
abs(GetBValue(Color1)-GetB
end;
...but this does not work very well.
How do I make this function in a better way?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Another alternative is recalculate RGB to more meaningfull coefficients like YUV and compare them