Harris Corner Detection Highlighting all edges not corners

  • Context:
  • Thread starter Thread starter NotASmurf
  • Start date Start date
  • Tags Tags
    Detection
Click For Summary
SUMMARY

The discussion focuses on implementing Harris corner detection, specifically addressing issues with thresholding R values. The user reports that using a threshold of R>0 results in no highlighted corners, while R<0 yields effective edge detection but no corners. The provided code utilizes functions for intensity calculation, matrix operations, and corner detection, including a Mask function that applies a threshold to identify significant points. The user later adds a windowing approach to refine detection but encounters challenges with point quantity.

PREREQUISITES
  • Understanding of Harris corner detection algorithms
  • Proficiency in C# programming and Bitmap manipulation
  • Familiarity with matrix operations and determinants
  • Knowledge of image processing concepts, particularly edge detection
NEXT STEPS
  • Implement and test different threshold values for R in Harris corner detection
  • Explore advanced windowing techniques to optimize corner detection
  • Learn about alternative corner detection algorithms such as Shi-Tomasi
  • Investigate the effects of varying window sizes on detection accuracy
USEFUL FOR

Image processing developers, computer vision researchers, and software engineers focused on enhancing edge and corner detection in digital images.

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;
        }
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 36 ·
2
Replies
36
Views
6K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 23 ·
Replies
23
Views
2K