1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
function ComputeGaussian(x, Sigma : Single) : Single;
begin
Result := System.exp(((-x * x) / ( 2 * Sigma * Sigma)));
end;
function ComputeLoG(x, Sigma : Single) : Single;
var
g : Single;
begin
g := ComputeGaussian(x,Sigma);
Result := (x * x - 2 * Sigma * Sigma) / (Math.power(Sigma,4)) * g;
end;
function ComputeLOGKernel(Var KernelSize : Integer; Weight : Single) : TBZDynSingleArray;
Var
KernelRadius : Integer;
x, y , i, j : Integer;
s, Sum, Dist, Theta, f, xx,yy : Single;
t, KSize : Integer;
//OutMatrix : Array of Single;
begin
s := weight - 0.8;
// t := Round(3.35 * s + 0.33);
//KernelSize := 2 * t + 1;
KernelRadius := KernelSize div 2;
KSize := KernelSize * KernelSize;
SetLength(Result, KSize );
Sum := 0;
Dist := 0;
for y := -KernelRadius to KernelRadius do
begin
j := (y + KernelRadius);
yy := y; //j - t;
yy := yy * yy;
j := j * KernelSize;
for x := -KernelRadius to KernelRadius do
begin
i := x + KernelRadius;
xx := x; //i - t;
xx := xx * xx;
Dist := System.Sqrt(xx + yy);
f := ComputeLOG(Dist, s);
Result[j + i] := f;
Sum := Sum + f;
end;
end;
// normalisation
Theta := 1.0 / Sum;
for x := 0 to (KSize-1) do Result[x] := Result[x] * Theta;
end; |
Partager