Skip to content

Instantly share code, notes, and snippets.

@sysint64
Created December 29, 2015 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sysint64/d05e55b1042bf5a8cab8 to your computer and use it in GitHub Desktop.
Save sysint64/d05e55b1042bf5a8cab8 to your computer and use it in GitHub Desktop.
function AverageGradientPoint (Gradient : TGradient; Point, Radius : Integer) : RGB;
var
i : Integer;
RGBSum : array[0..2] of Integer;
const
R = 0; G = 1; B = 2;
begin
RGBSum[R] := 0; RGBSum[G] := 0; RGBSum[B] := 0;
for i := Point-Radius to Point+Radius do
begin
RGBSum[R] := RGBSum[R]+Gradient.Data[i][R];
RGBSum[G] := RGBSum[R]+Gradient.Data[i][G];
RGBSum[B] := RGBSum[R]+Gradient.Data[i][B];
end;
Result := RGB (RGBSum[R] div Radius, RGBSum[G] div Radius, RGBSum[B] div Radius);
end;
function NormalizeGradient (Gradient : TGradient; Norm, Radius : Integer) : TGradient;
var
i, j : Integer;
Step : Integer;
begin
Result := TGradient.Create (Norm);
Step := Gradient.Size div Norm;
i := 0;
j := 0;
while (1) do
begin
Result.Data[i] := AverageGradientPoint (Gradient, j, Radius);
Inc (i); j := j+Step;
end;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment