download filterNonMaximaSuppression.pas
Language: Delphi
Copyright: (C) 2004 Durand Emmanuel (C) 2004 Burgel Eric
LOC: 58
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 filterNonMaximaSuppression;
(* ***** 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, abstractfilterNeighbor3;

type
  TFilterNonMaximaSuppression = class(TAbstractfilterNeighbor3)
  public
    constructor Create; override;
    destructor Destroy; override;
    procedure Run(); override;
    procedure ProcessNeighbor3(); override;
  private
    bOutpuColorWhite : Boolean;
  end;

implementation
uses
  imageIO, Math;

constructor TFilterNonMaximaSuppression.Create;
begin
  inherited;
end;

destructor TFilterNonMaximaSuppression.Destroy;
begin
end;

procedure TFilterNonMaximaSuppression.Run();
begin
  bOutpuColorWhite := True;
  if parameterOutputColor.Value='UNCHANGED' then bOutpuColorWhite:=False;
  inherited;
end;

procedure TFilterNonMaximaSuppression.ProcessNeighbor3();
var
  nucleusIntensity : Byte;
  nucleusIsMax : Boolean;
  c, nucleusColor : TColor32;
begin
  nucleusIntensity := Byte(NeighborRow0^[IndexCol0]);
  nucleusIsMax := True;
  if Byte(NeighborRowDec1^[IndexColDec1])>=nucleusIntensity then nucleusIsMax := False
  else if Byte(NeighborRowDec1^[IndexCol0])>=nucleusIntensity then nucleusIsMax := False
  else if Byte(NeighborRowDec1^[IndexColInc1])>=nucleusIntensity then nucleusIsMax := False
  else if Byte(NeighborRow0^[IndexColDec1])>=nucleusIntensity then nucleusIsMax := False
  else if Byte(NeighborRow0^[IndexColInc1])>=nucleusIntensity then nucleusIsMax := False
  else if Byte(NeighborRowInc1^[IndexColDec1])>=nucleusIntensity then nucleusIsMax := False
  else if Byte(NeighborRowInc1^[IndexCol0])>=nucleusIntensity then nucleusIsMax := False
  else if Byte(NeighborRowInc1^[IndexColInc1])>=nucleusIntensity then nucleusIsMax := False;
  if nucleusIsMax=True then begin
    if bOutpuColorWhite=True then begin
      c := clWhite32;
    end else begin
      c := clWhite32; // nucleusColor
    end;
  end else begin
    c := clBlack32;
  end;
  dest^[0] := c;
end;

{
procedure TFilterNonMaximaSuppression._run();
var
  pSrc, PDest : PColor32Array;
  w,h :Integer;
  value : Integer;
  tIntensity, tIntensityMax : Integer;
  tIntensityNucleus : Integer;
  neighbor :Integer;
  imageSrcRow, imageSrcCol : Integer;
  imageSrcRowmax, imageSrcColmax : Integer;
  imageSrcNeighborRow, imageSrcNeighborCol : Integer;
  imageSrcNeighborRowmin, imageSrcNeighborColmin : Integer;
  imageSrcNeighborRowmax, imageSrcNeighborColmax : Integer;
  c, nucleusColor : TColor32;
  bOutpuColorWhite : Boolean;
  deltaWithNearest, nearest_x, nearest_y, max_x, max_y : Integer;
  delta : Integer;
begin
  bOutpuColorWhite := True;
  if parameterOutputColor.Value='UNCHANGED' then bOutpuColorWhite:=False;
  h := parameterImageIn.Image.Height;
  w := parameterImageIn.Image.Width;
  neighbor := 1;
  pSrc := parameterImageIn.Image.Bits;
  imageSrcRowmax := h-1;
  imageSrcColmax := w-1;
  for imageSrcRow:=0 to imageSrcRowmax do begin
    pDest := parameterImageOut.Image.Bits;
    Inc(pDest,imageSrcRow*w);
    for imageSrcCol:=0 to imageSrcColmax do begin
      c := clBlack32;
      nucleusColor := pSrc[imageSrcRow*w+imageSrcCol];
      tIntensityNucleus := nucleusColor and $000000FF;//tIntensityNucleus:=Intensity(value);
      if tIntensityNucleus>0 then begin
        //
        tIntensityMax := -1;
        deltaWithNearest := 255;
        imageSrcNeighborRowmin := imageSrcRow-neighbor; if imageSrcNeighborRowmin<0 then imageSrcNeighborRowmin:=0;
        imageSrcNeighborColmin := imageSrcCol-neighbor; if imageSrcNeighborColmin<0 then imageSrcNeighborColmin:=0;
        imageSrcNeighborRowmax := imageSrcRow+neighbor; if imageSrcNeighborRowmax>imageSrcRowmax then imageSrcNeighborRowmax:=imageSrcRowmax;
        imageSrcNeighborColmax := imageSrcCol+neighbor; if imageSrcNeighborColmax>imageSrcColmax then imageSrcNeighborColmax:=imageSrcColmax;
        for imageSrcNeighborRow := imageSrcNeighborRowmin to imageSrcNeighborRowmax do begin
          for imageSrcNeighborCol :=imageSrcNeighborColmin to imageSrcNeighborColmax do begin
            value := pSrc[imageSrcNeighborRow*w+imageSrcNeighborCol];
            tIntensity := value and $000000FF;//tIntensity:=Intensity(value);
            // search the maximum
            if tIntensity > tIntensityMax then begin
              tIntensityMax := tIntensity;
              max_x := imageSrcNeighborCol;
              max_y := imageSrcNeighborRow;
            end;
            // search the nearest
            delta := Abs( tIntensity-tIntensityNucleus );
            if deltaWithNearest>delta then begin
              deltaWithNearest := delta;
              nearest_x := imageSrcNeighborCol;
              nearest_y := imageSrcNeighborRow;
            end;
          end;
        end;
        // if the current nucleus is the maximum
        // or, if the current nucleus is not the maximum but if it is the nearest of a maximum
        if (tIntensityNucleus=tIntensityMax) or
           ((nearest_x=max_x) and (nearest_y=max_y)) then begin
          if bOutpuColorWhite=True then begin
            c := clWhite32;
          end else begin
            c := nucleusColor;
          end;
        end;
      end;
      // set gray value with Color32 for optimization
      pDest^[0]:= c;
      Inc(pDest);
    end;
  end;
end;
}

end.

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