Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function TFloatMatrix.Normalize(Alpha:Single=0.0; Beta:Single=1.0): TFloatMatrix;
- var
- Lo,Hi,oldRange,newRange:Single;
- X,Y,W,H: Int32;
- begin
- H := High(Self);
- W := High(Self[0]);
- SetLength(Result, H+1,W+1);
- lo := $FFFFFF;
- hi := -$FFFFFF;
- for Y:=0 to H do
- for X:=0 to W do
- begin
- if self[y,x] < lo then lo := self[y,x];
- if self[y,x] > hi then hi := self[y,x];
- end;
- oldRange := Hi-Lo;
- newRange := Beta-Alpha;
- for Y:=0 to H do
- for X:=0 to W do
- Result[Y,X] := (Self[Y,X] - lo) / oldRange * newRange + Alpha;
- end;
- procedure BuildHeatmap(BMP: TMufasaBitmap; Mat: TFloatMatrix);
- var
- _h,_l:Extended;
- W,H,x,y,color:Int32;
- begin
- W := Length(Mat[0])-1;
- H := Length(Mat)-1;
- Mat := Mat.Normalize(0,1);
- BMP.SetSize(W+1,H+1);
- for y:=0 to H do
- for x:=0 to W do
- begin
- _h := (1 - Mat[y,x]) * 100;
- _l := Mat[y,x] * 50;
- color := HSLToColor(_H,100,_L);
- BMP.SetPixel(x,y, color);
- end;
- end
- var
- BMP1,BMP2: TMufasaBitmap;
- begin
- BMP1 := GetMufasaBitmap(LoadBitmap('tests/lena++.png'));
- BMP2 := GetMufasaBitmap(LoadBitmap('tests/lena_sub.png'));
- BuildHeatmap(BMP1, ex.MatchTemplate(BMP1, BMP2, 5));
- BMP1.Debug();
- BMP1.Free();
- BMP2.Free();
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement