SRL Archive - Research & Development Lounge

GetBestTolerance


Richard

2012-01-13 16:32:51

Been doing a little bit of research into finding what the best tolerance is for colour finding techniques is. I had this idea of logging in and out many times and grabbing colours of the same pixel. I then thought of making this function that takes all the colours, and then calculates a tolerance that would be able to find all of the given colours with any of the colours used in the function.
Note: This only works using CTS 1 (RGB):

function GetBestTolerance(Colors: TIntegerArray): Integer;
var
vals: Array [0..2] of Array of Integer;
low,high: Array [0..2] of Byte;
differences: array [0..2] of Integer;
i: Integer;
begin
for i := 0 to 2 do
SetArrayLength(vals[i],Length(Colors));
for i := 0 to Length(Colors) - 1 do
ColorToRGB(Colors[i], vals[0][i], vals[1][i], vals[2][i]);
for i := 0 to 2 do
begin
low[i] := MinA(vals[i]);
high[i] := MaxA(vals[i]);
differences[i] := high[i] - low[i];
end;
Result := MaxA(differences);
end;

I did a couple of tests, using the colours below:
The colour pairs here are 36095/42495 and 16711680/14772545.

The results given are 25 and 105. Even though the blue pairs are quite similar, either the green or red values must change a lot.


If I am to make this more effective, I need to work with CTS2 and CTS3, the problem is that I don't know how the tolerances for HSL and XYZ work, if someone could tell me how their tolerances work, then I'd be able to adapt this function (so it has CTS in the parameters) to work with more accurate CTSs.

Thanks.

mormonman

2012-01-13 16:38:58

You can look in Autocolor.simba and there is a function there that has CTS2.

nielsie95

2012-01-13 17:15:24

That's for cts 0, actually :)
Here's how I do it.

Richard

2012-01-13 17:18:53

From: nielsie95
That's for cts 0, actually :)
Here's how I do it.


I thought CTS1 was RGB? Proves how little I actually know about how our colour searching works :p What's different about CTS1?

nielsie95

2012-01-13 17:22:14

They both use RGB, but cts 0 uses absolute difference, while cts 1 uses Euclidean distance.

(Abs(R1 - R2) <= Tol) and (Abs(G1 - G2) <= Tol) and (Abs(B1 - B2) <= Tol)

versus

Sqrt(Sqr(R1 - R2) + Sqr(G1 - G2) + Sqr(B1 - B2)) <= Tol

Richard

2012-01-13 17:47:42

From: nielsie95
They both use RGB, but cts 0 uses absolute difference, while cts 1 uses Euclidean distance.

(Abs(R1 - R2) <= Tol) and (Abs(G1 - G2) <= Tol) and (Abs(B1 - B2) <= Tol)

versus

Sqrt(Sqr(R1 - R2) + Sqr(G1 - G2) + Sqr(B1 - B2)) <= Tol


Ah, that makes far more sense. I'll adapt this to that. How do the tolerances work on HSL/XYZ? Looking through them, I'm assuming that they have defaults for the HS values, that you define yourself, but how does the lightness work?

nielsie95

2012-01-13 17:53:05

Hue, Saturation and Luminance each have their own tolerance. You only pass the L tolerance. HueTol = HueMod * Tol, SatTol = SatMod * Tol. And then compare the absolute difference. Hue tolerance is calculated circle wise (with a max of 100, so 101 is very close to 1). You can find all this in the Simba source and a way to calculate the best tolerance in the link above.

funnyman9292

2012-01-16 18:47:46

Why not just add it to the startup of the script?