unit filterVectorHistogram;
(* ***** BEGIN LICENSE BLOCK *****
* Copyright (C) 2004 Durand Emmanuel
* Copyright (C) 2004 Burgel Eric
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact :
* filters@edurand.com
* filters@burgel.com
*
* ***** END LICENSE BLOCK ***** *)
{
edurand (filters@edurand.com)
eburgel (filters@burgel.com)
}
interface
uses
filter, fparameters, image, windows;
type
TFilterVectorHistogram = class(TFilter)
public
constructor Create; override;
destructor Destroy; override;
procedure Run(); override;
private
parameterVectorArray : TParameterPointer;
parameterAnglePrecision : TParameterInteger;
parameterSmooth : TParameterInteger;
outputparameterImageOut : TParameterImage;
outputparameterVectorHistogram : TParameterArraySingles;
outImage : PBitmap32;
anglePrecision, smooth : Integer ;
vectorChain : array of TFVector;
vectorHistogram : Array of Single;
procedure _run();
procedure createVectorHistogram();
procedure viewVectorHistogram();
end;
implementation
uses
imageIO, Math, divers;
constructor TFilterVectorHistogram.Create;
begin
inherited;
parameterVectorArray:=addParameterPointer('vectorArray','a pointer on a array of TFVector object, provides for example by TFilterBlobExplorer');
parameterAnglePrecision:=addParameterInteger('anglePrecision', 'The number of different bin to class all angle (0->360 degrees). For example, set 360 to have 1 bin by degre, or set 3600 to have 10 bins by degre.', 1, 36000, 360) ;
parameterSmooth:=addParameterInteger('smooth', 'smooth', 0, 50, 10) ;
outputparameterImageOut := addOutputParameterImage('outImage', 'outImage');
outputparameterVectorHistogram:=addOutputParameterArraySingles('vectorHistogram','vector histogram array, of type Single');
end;
destructor TFilterVectorHistogram.Destroy;
begin
image.freeImage(outImage);
inherited;
end;
procedure TFilterVectorHistogram.run();
begin
anglePrecision := parameterAnglePrecision.Value;
smooth := parameterSmooth.Value;
vectorChain := parameterVectorArray.Value;
if (vectorChain<>nil) then begin
_run();
end;
end;
procedure TFilterVectorHistogram._run();
begin
createVectorHistogram();
viewVectorHistogram();
setOutputParameterImage('outImage',outImage);
setOutputParameterArraySingles('vectorHistogram',vectorHistogram);
end;
procedure TFilterVectorHistogram.createVectorHistogram();
var
x : integer ;
i, iMax : Integer ;
index : integer ;
h2 : Array of Extended ;
vector : TFVector ;
scale : Extended ;
angleDegre : Single;
factor : Single;
begin
scale := 5 ;
setLength(vectorHistogram, anglePrecision);
setLength(h2, anglePrecision);
// initialize to 0
for x:=0 to anglePrecision-1 do vectorHistogram[x] := 0 ;
for x:=0 to anglePrecision-1 do h2[x] := 0 ;
factor:=anglePrecision/360;
// Create the vector histogram
iMax:=Length(vectorChain)-1;
for i:=0 to iMax do begin
vector := vectorChain[i] ;
angleDegre:=RadToDeg(vector.angle);
index := Floor(angleDegre * factor);
vectorHistogram[index] := vectorHistogram[index] + vector.length*Scale ;
end ;
smoothIt(vectorHistogram, smooth) ;
end ;
procedure TFilterVectorHistogram.viewVectorHistogram();
var
x, y : integer ;
begin
image.freeImage(outImage);
outImage:=image.createImage(anglePrecision,200);
for x:=0 to anglePrecision-1 do Begin
y := round(vectorHistogram[x]) ;
if y >= 200 then y := 199 ;
image.drawLine(outImage, x, 199, x, 199-y, clRed32);
end ;
end ;
end.