Harris Corner Detection Highlighting all edges not corners

  • Thread starter Thread starter NotASmurf
  • Start date Start date
  • Tags Tags
    Detection
AI Thread Summary
The discussion revolves around the implementation of Harris corner detection, highlighting issues with the output when applying a threshold to the R values. The user reports that setting a threshold of R > 0 yields no highlighted corners, while using R < 0 produces effective edge detection but fails to identify corners. The code provided includes functions for calculating intensity, trace, determinant, and the R value, as well as methods for creating intensity matrices and applying a mask based on thresholds.After realizing the need for windowing, the user added a new function, MaskWindow, to refine corner detection. However, this adjustment resulted in either too many or too few detected points, working well for a checkerboard pattern but not for other shapes. The user seeks assistance in optimizing the corner detection process to achieve better results across various image types.
NotASmurf
Messages
150
Reaction score
2
I need to implement Harris corner detection, which should only have positive R values, if i use threshold of R>0, it highlights nothing, if R<0 however, from even -0.00001 to -1000000 it outputs perfect edge detection, but no corners, ANY help appreciated.

Input and output:http://imgur.com/a/TtQSD\

Main Code:

Code:
Bitmap b = (Bitmap)pictureBox1.Image;
 var i = IntensityMat(b);
 var n = Mask(i,-0.00000001);
 var ty = ToBit(n);
 pictureBox1.Image = ty;
[/NOPARSE]
Functions:
Code:
public double Intensity(Color c)
   {
       int x = c.R;
       int y = c.G;
       int z = c.B;
       return Math.Sqrt(x * x + y * y + z * z);
   }

   public double Trace(double[,] m)
   {
       double sum = 0;

       for (int i = 0; i < m.GetLength(0); i++)
       {
           sum += m[i, i];
       }

       return sum;
   }

   public double[,] M(double ix,double iy)
   {
       double[,] m = new double[2, 2];

       m[0, 0] = ix*ix;
       m[1, 1] = iy*iy;
       m[0, 1] = ix * iy;
       m[1, 0] = ix * iy;

       return m;
   }

   public double Det(double[,] m)
   {
       return m[1, 1] * m[0, 0] - m[0, 1] * m[1, 0];
   }

   public double R(double[,] m,double k=0.04)
   {
       var t = Trace(m);
       return Det(m) - k * t * t;
   }

   int[,] IntensityMat(Bitmap b)
   {
       int[,] n = new int[b.Width, b.Height];

       for (int i = 0; i < b.Width; i++)
       {
           for (int j = 0; j < b.Height; j++)
           {
               Color c = b.GetPixel(i, j);
               n[i, j] = (int)Intensity(c);
           }
       }

       return n;
   }

   Bitmap ToBit(int[,] bd)
   {
       Bitmap b = new Bitmap(bd.GetLength(0), bd.GetLength(1));
       for (int i = 0; i < b.Width; i++)
       {
           for (int j = 0; j < b.Height; j++)
           {
               var t = bd[i, j];
               b.SetPixel(i, j, Color.FromArgb(t, t, t));
           }
       }

       return b;
   }

   int[,] Mask(int[,] m,double thresh)// m matrix of I
   {
       int[,] n = new int[m.GetLength(0), m.GetLength(1)];

       for (int i = 1; i < m.GetLength(0); i++)
       {
           for (int j = 1; j < m.GetLength(1); j++)
           {
               double ix = Math.Abs(m[i-1,j]-m[i,j]);
               double iy = Math.Abs(m[i , j-1] - m[i, j]);

               var lap = M(ix, iy);
               var r = R(lap);

               if (r > thresh)
               {
                   n[i, j] = 255;
               }
           }
       }

       return n;
   }
[/NOPARSE]
 
Technology news on Phys.org
So turns out i forgot to do windowing xP, added code beneath, but now it either gets too many points, or not enough, http://imgur.com/a/7I899
it works for a checkerboard, but not those squares O.o

Code:
 int[,] MaskWindow(int[,] m, double thresh,int window,out List<Point> p)// m matrix of I
        {
            List<Point> ff = new List<Point>();
            int[,] n = new int[m.GetLength(0), m.GetLength(1)];
           
            for (int i = 1; i < m.GetLength(0)-window; i+=window)
            {
                for (int j = 1; j < m.GetLength(1)-window; j+=window)
                {
                   
                    double[,] sumM = new double[2, 2];
                    for(int k = 0; k < window; k++)
                    {
                        for (int k2 = 0; k2 < window; k2++)
                        {
                            double ix = Math.Abs(m[i - 1+k, j+k2] - m[i+k, j+k2]);
                            double iy = Math.Abs(m[i+k, j - 1+k2] - m[i+k, j]+k2);
                            sumM = SumMat(sumM, M(ix, iy));
                        }
                    }
                    var lap = sumM;
                    var r = R(lap);

                    if (r > thresh)
                    {
                        ff.Add(new Point(i, j));
                        n[i, j] = 255;
                    }                }
            }
            p = ff;
            return n;
        }
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
5
Views
2K
Replies
7
Views
2K
Replies
2
Views
2K
Replies
5
Views
1K
Replies
22
Views
3K
Back
Top