SRL Archive - OSR Help

Color tolerance


pjwaffle

2010-09-12 19:54:45

I don't quite understand color tolerance, and what it should be at generally.

Also, how does color finding not mistake something for other things on the screen???

Coh3n

2010-09-12 22:29:28

From: pjwaffle
I don't quite understand color tolerance, and what it should be at generally.

Also, how does color finding not mistake something for other things on the screen???

Tolerance is like accuracy. If you're trying to find a color with a tolerance of 0, it will only find that color, but if you have a tolerance of 10, then it will find the original color plus colors that are close to that color.

And color finding can mistake one thing for another on the screen, that's why there are failsafes like uptext. If the mouse was to hover the wrong object, it wouldn't click if the uptext was wrong.

It also helps if you're using CTS 2/3 which makes it more accurate than CTS 1. See some guides on ColoerToleranceSpeeds in the tutorial section. ;)

Cstrike

2010-09-12 23:08:27

I'd like to know how tolerance works as a mechanism one day. For example, can anyone predict the range of colors it will search when attempting to find Color 1000000 with a tolerance of 5?

Nava2

2010-09-12 23:22:49

it searches withing 5 of the RGB values.

So if you had (213,100,134) and searched with tol of 3, (210->216, 97->103,131->137) would be valid.

E: thats only with CTS zero and one.

Wanted

2010-09-12 23:30:56

From: pjwaffle
I don't quite understand color tolerance, and what it should be at generally.

Also, how does color finding not mistake something for other things on the screen???


From: cstrike
I'd like to know how tolerance works as a mechanism one day. For example, can anyone predict the range of colors it will search when attempting to find Color 1000000 with a tolerance of 5?


Colors in their decimal form are like 16777215, 255, 0 (white, red, black) and all colors are composed generally of three or four elements.

Like for example 255 (clRed) is 255 red 0 green 0 blue

16777215 (clWhite) is 255 red 255 green 255 blue

You get the picture, now of course there is more than RGB (red green blue) there is HSL (hue saturation luminance) XYZ, LAB… the list goes on.

Now colors (in runescape particularly) are designed to fluctuate. When you call a simple FindColor or GetColor() = 000000 in SCAR it's only going to return true if that exact same color was found. So in order to compensate for this we add in a thing called tolerance. What it does it determines the range of say a Max Red, Min Red, Max Green, Min Green, Max Blue, Min Blue of a color…. now depending on which CTS (color tolerance speed) you use the tolerance level will be different and target different types of color fluctuations.

Straight out of SCAR manual

procedure ColorToleranceSpeed(x: Integer);
Sets the speed of tolerance comparisons. ColorToleranceSpeed(1) is a little slower then 0 but more accurate. ColorToleranceSpeed(0) is faster but not as accurate as 1. ColorToleranceSpeed(2) uses Hue, Saturation and Lightness to determine color similarity. ColorToleranceSpeed(3) uses the CIE colorspace to compare colors (XYZ), it's usually fairly slower than the other modes but it's extremely accurate.


To get a better understanding and to know how much tolerance you should use for a certain thing, there is a thing called ACA (auto color aid) it can be found in tools -> explorer folder -> includes -> SRL -> scripting tools.

There's also various tutorials on this in the scripting tutorial sections.

Cstrike

2010-09-13 00:36:53

I use ACA aid a lot, it's great for making FindObj stuff.

What I don't understand from the above would be:
- What is decimal form of a color?
- How is 255/255/255 rgb = 16777215? Does that apply to the 16777215,255,0?
- How can there be a 16777215, 255, 0 (white, red, black), I thought they went up to 255 only
- If we have color x as something like 600000, if we subtract one, will it look sort of like the same color? Or could it vary wildly by just increasing the longint by 1?

I've actually been looking for tutorials on color. I feel lost without understanding *exactly* how color works. I know I can just use ACA for pretty much everything, but it leaves a huge gap in my knowledge of how and why it works. Pretty much, I'm like a physicist who can make a rocket go into space without knowing d/t=v.
I've looked through probably most guides as I attempted [and succeeded] at getting into SRL members. Now it's time to fill in all these gaps. I'd like to be more proficient with color too, and I'm sure this will aid me a lot :)
If you have any links that explain everything in the most minute of detail I will read [or re-read!] again with precision.


EDIT: Another reason tolerance can be confusing for me is because according to This tutorial, color tolerance is basically RANGE = COLOR - TOLERANCE, yet when I set a tolerance of 50 or 100… or even 300… it will cover the whole screen pretty much in red; thus confusing me on how tolerance works since I know all of the pixels are not 300 units away from the color chosen.

Wanted

2010-09-13 02:20:43

From: cstrike

- What is decimal form of a color?
- How is 255/255/255 rgb = 16777215? Does that apply to the 16777215,255,0?
- How can there be a 16777215, 255, 0 (white, red, black), I thought they went up to 255 only
- If we have color x as something like 600000, if we subtract one, will it look sort of like the same color? Or could it vary wildly by just increasing the longint by 1?


white red black? It's Red Green Blue. The color 60000 is potentially very much different from 60001 such as green -> red (open the DTM editer up and manually edit the color value to change the preview, you'll see what I mean).

Colors in decimal form are this way because of bitwise operations http://villavu.com/forum/showthread.php?t=18514
http://villavu.com/forum/showthread.php?t=55234 (simpler)

Wizzup?

2010-09-13 03:05:47

Tolerance is just a formula that we use to define how similar colours are. If they are very similar, the tolerance will be low, if they are not at all similar, the tolerance will have to be high to match them. This makes it easy for example to find colour that look ``red''.

From: IceFire908
Straight out of SCAR manual


I never found the SCAR manual to give a pleasing description of each tolerance, so here's my try at quickly describing the tolerances in Simba: http://wizzup.org/simbadoc/scriptref/colourfinding.html#colour-tolerance
(The entire article may be of use for the OP)

For an even better understanding of the algorithms, we take a look at the Simba source:


function TMFinder.SimilarColors(Color1, Color2,Tolerance: Integer) : boolean;
var
R1,G1,B1,R2,G2,B2 : Byte;
H1,S1,L1,H2,S2,L2 : extended;
begin
Result := False;
ColorToRGB(Color1,R1,G1,B1);
ColorToRGB(Color2,R2,G2,B2);
if Color1 = Color2 then
Result := true
else
case CTS of
0: Result := ((Abs(R1-R2) <= Tolerance) and (Abs(G1-G2) <= Tolerance) and (Abs(B1-B2) <= Tolerance));
1: Result := (Sqrt(sqr(R1-R2) + sqr(G1-G2) + sqr(B1-B2)) <= Tolerance);
2: begin
RGBToHSL(R1,g1,b1,H1,S1,L1);
RGBToHSL(R2,g2,b2,H2,S2,L2);
Result := ((abs(H1 - H2) <= (hueMod * Tolerance)) and (abs(S2-S1) <= (satMod * Tolerance)) and (abs(L1-L2) <= Tolerance));
end;
end;
end;

bugger0001

2010-09-16 05:35:41

Nice! This one got me interested as well. Any tips where could I find the sources for ColorToRGB and RGBToHSL ?

Shuttleu

2010-09-16 05:45:37

From: Wizzup?


Result := ((abs(H1 - H2) <= (hueMod * Tolerance)) and (abs(S2-S1) <= (satMod * Tolerance)) and (abs(L1-L2) <= Tolerance));


sorry, but where does hueMod and satMod come from?

~shut

bugger0001

2010-09-16 05:56:31

If you use CTS2 then you define those as globals, i suppose…

Wizzup?

2010-09-16 09:44:15

From: bugger0001
Nice! This one got me interested as well. Any tips where could I find the sources for ColorToRGB and RGBToHSL ?


Here. https://git.villavu.com/?p=simba.git;a=blob;f=Units/MMLCore/colour_conv.pas;

hueMod and satMod default to 0.2, Shuttleu. :)

bugger0001

2010-09-17 07:25:29

Thanks! That cleared out couple of issues I had with colours ;)

Cazax

2010-09-17 12:47:28

From: Shuttleu
sorry, but where does hueMod and satMod come from?

~shut

It's a predefined variable IIRC. So when you change hueMod and satMod in your script(SetToleranceSpeed2Modifiers) it's also modified inside Simba. :)