download abstractfilterNeighbor3.pas
Language: Delphi
Copyright: (C) 2004 Durand Emmanuel (C) 2004 Burgel Eric
LOC: 82
Project Info
Filters
Server: SourceForge
Type: cvs
...ilters\Filters1\Src\Delphi\
   ...ractfilterNeighbor3.pas
   Chronometer.pas
   divers.pas
   filter.pas
   filterAdjust.pas
   filterArithmeticAdd.pas
   ...ithmeticConstantAdd.pas
   ...ArithmeticSubstract.pas
   filterBlobBalance.pas
   filterBlobExplorer.pas
   filterBlobGrouping.pas
   ...erBlobRepositioning.pas
   ...rBlobRepositioning2.pas
   filterBlur.pas
   filterCanny.pas
   filterContour.pas
   filterContrastExplorer.pas
   filterConvolution.pas
   filterCoocurenceMatrix.pas
   filterCopy.pas
   filterCorrelation.pas
   filterCutter.pas
   filterDistancesMap.pas
   filterExplorer.pas
   ...nisotropicDiffusion.pas
   ...GranularityExplorer.pas
   filterHistogram.pas
   ...erHistogramContrast.pas
   filterImageCreator.pas
   filterImageLoader.pas
   filterImageSaver.pas
   filterIntegration.pas
   filterInvert.pas
   filterLocalDeviation.pas
   filterLogPolar.pas
   filterMedian.pas
   filterMorphology.pas
   ...onMaximaSuppression.pas
   filterNormalize.pas
   filterOnOffCell.pas
   filterProjectionLine.pas
   filterPyramid.pas
   filterRescaleIntensity.pas
   filterResize.pas
   filterRotation.pas
   filterSigmoid.pas
   filterSmoothBilateral.pas
   filterSobel.pas
   filterSPV.pas
   filterStackProcessor.pas
   filterStackSmasher.pas
   ...erStandardDeviation.pas
   filterSUSAN.pas
   filterThresholdBinary.pas
   filterVectorHistogram.pas
   filterWavelets.pas
   filterWaves.pas
   fmask.pas
   fparameters.pas
   image.pas
   imageIO.pas
   imageIOVideo.pas
   lacModel.pas
   polygonalyzation.pas
   wrapper_itk.pas
   wrapper_opencv.pas

unit abstractfilterNeighbor3;
(* ***** 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
 * Site :
 *   http://filters.sourceforge.net/
 *
 * ***** END LICENSE BLOCK ***** *)

{
 edurand (filters@edurand.com)
}

interface
uses
  filter, fparameters, image, SysUtils, filterCopy;

type
  TAbstractfilterNeighbor3 = class(TFilter)
  public
    dest : PColor32Array;
    NeighborRowDec1, NeighborRow0, NeighborRowInc1 : PColor32Array;
    IndexColDec1, IndexCol0, IndexColInc1 : Integer;
    constructor Create; override;
    destructor Destroy; override;
    procedure Run(); override;
    procedure ProcessNeighbor3(); virtual; abstract;
  protected
    parameterImageIn, parameterImageOut : TParameterImage;
    parameterOutputColor : TParameterString;
  private
    filterCopy : TFilterCopy;
    imageIntensity : PBitmap32;
    procedure _run();
  end;

implementation
uses
  imageIO, Math;

constructor TAbstractfilterNeighbor3.Create;
begin
  inherited;
  filterCopy := TFilterCopy.Create;
  parameterImageIn := addParameterImage( 'inImage', 'image to process' );
  parameterImageOut := addParameterImage( 'outImage', 'output image' );
  parameterOutputColor := addParameterString( 'outputColor', 'UNCHANGED/WHITE', 'WHITE' );
  IndexColDec1 := 0;
  IndexCol0 := 1;
  IndexColInc1 := 2;
end;

destructor TAbstractfilterNeighbor3.Destroy;
begin
  filterCopy.Free;
end;

procedure TAbstractfilterNeighbor3.Run();
begin
  if (parameterImageIn.Image<>nil) then begin
    _run();
  end;
end;

procedure TAbstractfilterNeighbor3._run();
var
  w,h :Integer;
  value : Integer;
  imageSrcRow, imageSrcCol : Integer;
  imageSrcRowmax, imageSrcColmax : Integer;
  p0 : Integer;
begin
  p0 := 0;
  h := parameterImageIn.Image.Height;
  w := parameterImageIn.Image.Width;
  imageSrcRowmax := h-1-1;
  imageSrcColmax := w-1-1;
  // convert color to gray intensity
  filterCopy.setParameterImage( 'inImage', parameterImageIn.Image );
  filterCopy.setParameterString( 'outputColor', 'INTENSITY' );
  filterCopy.Run;
  imageIntensity := filterCopy.getOutputParameterImage( 'outImage' ).Image;
  // process
  for imageSrcRow:=0 to imageSrcRowmax do begin
    NeighborRowDec1 := imageIntensity.Bits;
    NeighborRow0 := imageIntensity.Bits;
    NeighborRowInc1 := imageIntensity.Bits;
    Inc( NeighborRowDec1, imageSrcRow*w );
    Inc( NeighborRow0, (imageSrcRow+1)*w );
    Inc( NeighborRowInc1, (imageSrcRow+2)*w );
    dest := parameterImageOut.Image.Bits;
    Inc(dest, (imageSrcRow+1)*w+1 );
    for imageSrcCol:=0 to imageSrcColmax do begin
      ProcessNeighbor3();
      Inc(dest);
      Inc(NeighborRowDec1);
      Inc(NeighborRow0);
      Inc(NeighborRowInc1);
    end;
  end;
end;

// example : sobel vertical
{
procedure TFilterNonMaximaSuppression.ProcessNeighbor3();
var
  value : Integer;
begin
  value := (-Byte(NeighborRowDec1^[IndexColDec1])-Byte(NeighborRowDec1^[IndexCol0])-Byte(NeighborRowDec1^[IndexColInc1]) + Byte(NeighborRowInc1^[IndexColDec1])+Byte(NeighborRowInc1^[IndexCol0])+Byte(NeighborRowInc1^[IndexColInc1])) div 6;
  if value>255 then value:=255
  else if value<0 then value:=0;
  dest^[0] := Gray32( value );
end;
}

// example : morphology dilate
{
procedure TFilterNonMaximaSuppression.ProcessNeighbor3();
var
  maxInentity : Byte;
begin
  maxInentity := 0;
  if Byte(NeighborRowDec1^[IndexColDec1])>maxInentity then maxInentity := Byte(NeighborRowDec1^[IndexColDec1]);
  if Byte(NeighborRowDec1^[IndexCol0])>maxInentity then maxInentity := Byte(NeighborRowDec1^[IndexCol0]);
  if Byte(NeighborRowDec1^[IndexColInc1])>maxInentity then maxInentity := Byte(NeighborRowDec1^[IndexColInc1]);
  if Byte(NeighborRow0^[IndexColDec1])>maxInentity then maxInentity := Byte(NeighborRow0^[IndexColDec1]);
  if Byte(NeighborRow0^[IndexCol0])>maxInentity then maxInentity := Byte(NeighborRow0^[IndexCol0]);
  if Byte(NeighborRow0^[IndexColInc1])>maxInentity then maxInentity := Byte(NeighborRow0^[IndexColInc1]);
  if Byte(NeighborRowInc1^[IndexColDec1])>maxInentity then maxInentity := Byte(NeighborRowInc1^[IndexColDec1]);
  if Byte(NeighborRowInc1^[IndexCol0])>maxInentity then maxInentity := Byte(NeighborRowInc1^[IndexCol0]);
  if Byte(NeighborRowInc1^[IndexColInc1])>maxInentity then maxInentity := Byte(NeighborRowInc1^[IndexColInc1]);
  dest^[0] := Gray32( maxInentity );
end;
}


end.

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us