Harris Corner Detection Highlighting all edges not corners

  • Thread starter NotASmurf
  • Start date
  • Tags
    Detection
In summary, you are attempting to implement Harris corner detection. The method involves using a threshold value to highlight positive R values. However, when using a threshold of R>0, nothing is highlighted. When using a threshold of R<0, perfect edge detection is achieved, but no corners are detected. You are seeking assistance with this issue and have provided code and images for reference. You have also attempted to use windowing to improve the results, but are still encountering issues such as too many or not enough points being detected.
  • #1
NotASmurf
150
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
  • #2
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;
        }
 

Related to Harris Corner Detection Highlighting all edges not corners

1. What is Harris Corner Detection?

Harris Corner Detection is a popular algorithm used in computer vision to identify features or points of interest in an image. These features, or corners, are locations where the intensity of an image changes significantly in all directions.

2. How does Harris Corner Detection work?

The algorithm works by comparing the intensity of small windows in an image and calculating the change in intensity for all possible directions. If there is a significant change in intensity in all directions, then it is considered a corner.

3. Why does Harris Corner Detection highlight edges instead of corners?

Harris Corner Detection is designed to identify points of interest in an image, which can include both corners and edges. However, due to the nature of the algorithm, it may also highlight edges that have a significant change in intensity in multiple directions.

4. How accurate is Harris Corner Detection?

The accuracy of Harris Corner Detection depends on various factors such as the quality of the image, the size of the window used for comparison, and the threshold for identifying corners. In general, it is a robust algorithm and can accurately detect corners in most images.

5. What are some applications of Harris Corner Detection?

Harris Corner Detection has various applications in computer vision, such as object detection and tracking, image stitching, and feature matching. It is also used in robotics for tasks like navigation and mapping.

Similar threads

  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
2
Replies
36
Views
4K
  • Programming and Computer Science
Replies
22
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
6
Views
9K
  • Programming and Computer Science
Replies
9
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
23
Views
1K
  • Programming and Computer Science
Replies
7
Views
2K
  • Programming and Computer Science
Replies
1
Views
693
Back
Top