Link to home
Start Free TrialLog in
Avatar of BdLm
BdLmFlag for Germany

asked on

FIND LOCAL MAXIMA

I need an effective algorithm for finding local maxima in my Hough accumulator

the procedure  HoughResultToParameterDynamic(aHoughResult :  THoughResult; Range : Real; var aHoughFinal : THoughFinal ) is showing  my current ideas , looking for the gradient ...  is this the right  way ????
///
///  Max_Array  2D Integer array  , very simple scan through the hole array
///
function MAX_2D ( aHoughResult :  THoughResult  ) : Integer;
var   n,m      :  Integer;
      i,j      :  Integer;
      max      :  Integer;
begin
     n := length(aHoughResult);
     m := length(aHoughResult[0]);

     max :=  aHoughResult[0][0];

     for i:= 0 to n -1 do
      for j := 0 to m-1 do
        if aHoughResult[i][j] > max then
             max :=aHoughResult[i][j];

     result :=  max;

end;





///
///  MEAN_Array  2D Integer array
///

function MEAN_2D_Local ( aHoughResult :  THoughResult; x_pos, y_pos, x_size, y_size : Integer   ) : Integer;
var   n,m      :  Integer;
      i,j      :  Integer;
      mean      :  Integer;
begin
     n := length(aHoughResult);
     m := length(aHoughResult[0]);

     mean := 0;

     if ((x_pos>=(n-x_size)) or (y_pos>=(m-y_size))) then
                         begin
                         result := 0;
                         exit;
                         end;


     for i:= x_pos to x_pos + x_size do
       for j := y_pos to y_pos + y_size do
                    mean :=mean + aHoughResult[i][j];

     result := round( mean / ((x_size+1) * (y_size+1))) ;

end;




///
///  MAX_Array  2D Integer array
///

function MAX_2D_Local ( aHoughResult :  THoughResult; x_pos, y_pos, x_size, y_size : Integer   ) : Integer;
var   n,m      :  Integer;
      i,j      :  Integer;
      max      :  Integer;
begin
     n := length(aHoughResult);
     m := length(aHoughResult[0]);



     if ((x_pos>=(n-x_size)) or (y_pos>=(m-y_size))) then
                         begin
                         result := 0;
                         exit;
                         end;

     max :=  aHoughResult[x_pos][y_pos];

     for i:= x_pos to x_pos + x_size do
       for j := y_pos to y_pos + y_size do
            if aHoughResult[i][j] > max then
                        max :=aHoughResult[i][j];

     result := max;

end;







///
///  Min_Array  2D Integer array
///
function MIN_2D ( aHoughResult :  THoughResult  ) : Integer;
var   n,m      :  Integer;
      i,j      :  Integer;
      min      :  Integer;
begin
     n := length(aHoughResult);
     m := length(aHoughResult[0]);

     min :=  aHoughResult[0][0];

     for i:= 0 to n -1 do
      for j := 0 to m-1 do
        if aHoughResult[i][j] < min then
                min :=aHoughResult[i][j];

     result :=  min;

end;



///
///  clear result array
///
function ResetArray (var aHoughResult :  THoughResult  ) : Integer;
var   n,m      :  Integer;
      i,j      :  Integer;
      min      :  Integer;
begin
     n := length(aHoughResult);
     m := length(aHoughResult[0]);

     min :=  aHoughResult[0][0];

     for i:= 0 to n -1 do
      for j := 0 to m-1 do
           aHoughResult[i][j] := 0 ;
     result := 1;

end ;



///
///     copy the Hough Accumulator into a 3D INT Array Data type
///     in :
///     aHoughResult   ->  the Hough accu
///     range [ 0..1]
///     out:
///     aHoughFinal     list of points above the max
///                     [x,y,z]
///
///
procedure  HoughResultToParameter(aHoughResult :  THoughResult; Range : Real; var aHoughFinal : THoughFinal );
var   n,m      : Integer;
      i,j      : Integer;
      xquer    : Integer;
      MAX      : Integer;
      MAXR     : Real;
      resultlen : Integer;
begin

     n := length(aHoughResult);
     m := length(aHoughResult[0]);

     resultlen := 0;

     Max := MAX_2D(aHoughResult);
     if ( max = 0)  then max := 1 ;


     MaxR :=  Max * Range;


     for i:= 0 to n-1 do
       for j:= 0 to m-1 do
         if (aHoughResult[i,j] > MaxR ) then
           begin

           setlength (aHoughFinal, resultlen+1);

           aHoughFinal[resultlen].x := i;

           aHoughFinal[resultlen].y := j;

           aHoughFinal[resultlen].z := aHoughResult[i,j];

           resultlen  := resultlen + 1;

           end;


end;



///
///    as above, but now with dynamic thresholding
///              http://homepages.inf.ed.ac.uk/rbf/HIPR2/histeq.htm
///              http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm
///
///

procedure  HoughResultToParameterDynamic(aHoughResult :  THoughResult; Range : Real; var aHoughFinal : THoughFinal );
var   n,m      : Integer;
      i,j      : Integer;
      xquer    : Integer;
      MAX      : Integer;
      Mean     : Integer;
      MAXR     : Real;
      resultlen : Integer;
      Grad     : Integer;
      Grad_Min : Integer;
begin

     n := length(aHoughResult);
     m := length(aHoughResult[0]);

     resultlen := 0;

     Grad_Min := 30 ;


     for i:= 0 to n-1 do
       for j:= 0 to m-1 do
       begin

       Max :=  MAX_2D_Local (aHoughResult, i,j, 10, 10 );

       mean := MEAN_2D_Local (aHoughResult, i,j, 10, 10 );

       Grad := (Max - Mean);

       MaxR :=  Max * Range;


         if ((aHoughResult[i,j] > MaxR ) and (Grad > Grad_min)) then
           begin

           setlength (aHoughFinal, resultlen+1);

           aHoughFinal[resultlen].x := i;

           aHoughFinal[resultlen].y := j;

           aHoughFinal[resultlen].z := aHoughResult[i,j];

           aHoughFinal[resultlen].Z1 := Round(MaxR);

           resultlen  := resultlen + 1;

           end;
        end;

end;

Open in new window

HOUGH-LOCAL-maxima.jpg
ASKER CERTIFIED SOLUTION
Avatar of Ephraim Wangoya
Ephraim Wangoya
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BdLm

ASKER

thanks fofr your your response, but that does not help , the point is to find the local maxima  - and I not sure how to improve the selection criteria -
I tried with the gradient F(x) - F(x+1) > threshold value , but this is not suffiecient as the peak is not a single point, sometimes a small area -
need something like image / line thinning in advance --

as the complete code is a Hough pattern recognition algo - any code reference how it is done here is helpful.

most of the hough code I found just take the Hough accu as it is ...  this is fine for the demo but not for real images
Why don't you use a conjugate gradient ?


Avatar of BdLm

ASKER

how to find maxima with this algo ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BdLm

ASKER

any chance for working pascal code for that problem  ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BdLm

ASKER

really missing some code i can immeadiatly follow -  anyhow thanks for discussion