Advertisement
WarPie90

Mat normalize

Nov 27th, 2014
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.45 KB | None | 0 0
  1. function TFloatMatrix.Normalize(Alpha:Single=0.0; Beta:Single=1.0): TFloatMatrix;
  2. var
  3.   Lo,Hi,oldRange,newRange:Single;
  4.   X,Y,W,H: Int32;
  5. begin
  6.   H := High(Self);
  7.   W := High(Self[0]);
  8.   SetLength(Result, H+1,W+1);
  9.  
  10.   Self.MinMax(Lo,Hi);  //returns the smallest and largest values
  11.   oldRange := Hi-Lo;
  12.   newRange := Beta-Alpha;
  13.   for Y:=0 to H do
  14.     for X:=0 to W do
  15.       Result[Y,X] := (Self[Y,X] - lo) / oldRange * newRange + Alpha;
  16. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement