unit filterCoocurenceMatrix;
(* ***** 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 ***** *)
interface
uses
filter, fparameters, image;
type
TFilterCoocurenceMatrix = class(TFilter)
public
constructor Create; override;
destructor Destroy; override;
procedure Run(); override;
private
parameterHorCoSize : TParameterInteger ;
parameterVerCoSize : TParameterInteger ;
parameterScale : TParameterSingle ;
outputParameterImageOut : TParameterImage;
parameterImageIn : TParameterImage ;
imageIn : PBitmap32;
imageOut : PBitmap32;
matrix : Array[0..255, 0..255] of Integer ;
procedure destroyImageOut();
end;
implementation
uses
imageIO, classes, StrUtils, SysUtils, fmask;
constructor TFilterCoocurenceMatrix.Create;
begin
inherited;
parameterHorCoSize := addParameterInteger('horCoSize', 'horizontale co-ocurence size', 0, 100, 1);
parameterVerCoSize := addParameterInteger('verCoSize', 'verticale co-ocurence size', 0, 100, 1);
parameterScale := addParameterSingle ('scale', 'scale', 0.01, 100, 1) ;
parameterImageIn:= addParameterImage('inImage', 'input image to analyse');
outputParameterImageOut := addOutputParameterImage('outImage', 'co-ocurence matrix image');
end;
destructor TFilterCoocurenceMatrix.Destroy;
begin
destroyImageOut();
inherited;
end;
procedure TFilterCoocurenceMatrix.destroyImageOut();
begin
image.freeImage(imageOut);
end;
procedure TFilterCoocurenceMatrix.Run();
var
horCoSize, vercoSize : Integer ;
pSrc, pSrc2, PDest : PColor32Array;
x, y, maxX, maxY : Integer ;
coX, coY : Integer ;
scale : Single ;
value : Integer ;
begin
destroyImageOut();
horCoSize := parameterHorCoSize.Value;
verCoSize := parameterVerCoSize.Value;
scale := parameterScale.Value;
imageIn := parameterImageIn.Image ;
imageOut := image.createImage(256, 256);
FillChar(matrix, sizeOf(Integer)*256*256, 0) ;
maxX := scanWidth(imageIn)-1-horCoSize ;
maxY := scanHeight(imageIn)-1-verCoSize ;
for y:=0 to maxY do begin
// Pointer on first pixel
pSrc := scanLine(imageIn, y) ;
// Pointer on second pixel
pSrc2 := pSrc ;
inc(pSrc2,horCoSize+verCoSize*imageIn.Width) ;
for x:=0 to maxX do begin
coX := Intensity(pSrc^[0]) ;
coY := Intensity(pSrc2^[0]) ;
inc(matrix[coX, coY]) ;
//matrix[coX, coY] := 100 ;
inc(pSrc) ;
inc(pSrc2) ;
end ;
end ;
PDest := scanLine(imageOut, 0) ;
for y:=0 to 255 do Begin
for x:=0 to 255 do Begin
value := round(matrix[x, y]*scale) ;
if value > 255 Then
PDest^[0] := 255
else
PDest^[0] := Gray32(value) ;
inc(PDest) ;
End ;
End ;
setOutputParameterImage('outImage', imageOut );
end;
end.