title: Harris Corner Detection
body: <p>I'm doing a program to detect corners using Harris method. The output of the method shows the corners. What I want to do is to apply thresholding to the image. This is my code:</p>
  
  <pre><code> % Create a mask for deteting the vertical edges 
   verticalMask = [-1 0 1;
              -2 0 2;
              -1 0 1]* 0.25;
  
  % Create a mask for deteting the horizontal edges 
  horisontalMask = [-1 -2 -1;
                0 0 0;
                1 2 1]* 0.25;
  
  % Create a mask for Gaussian filter(is used to improve the result)
  
  gaussianFilter= [1 4 1;
               4 7 4;
               1 4 1].*(1/27);
  
  
  K = 0.04; % The sensitivity factor used in the Harris detection algorithm (Used to detect
              sharp corners).
  
  
  
  % Get the gradient of the image [Ix,Iy], using the convulation function
  Ix = conv2(grayImage,verticalMask);
  Iy = conv2(grayImage,horisontalMask);
  
  
  % get the input arguments of the harris formula
  
  Ix2 = Ix.* Ix; % get Ix to the power of two
  Iy2 = Iy.* Iy; % get Iy to the power of two
  Ixy = Ix .* Iy; %get the Ixy by multiply Ix and Iy
  
  % Apply the gaussian filter to the the arguments
  Ix2 = conv2(Ix2,gaussianFilter);
  Iy2 = conv2(Iy2,gaussianFilter);
  Ixy = conv2(Ixy,gaussianFilter);
  
  % Enetr the arguments into the formula
  C = (Ix2 .* Iy2) - (Ixy.^2) - K * ( Ix2 + Iy2 ).^ 2;
  </code></pre>
  
  <p>Now, I want to apply the thresholding to C which is the output of the formula. 
  I found a code that I tried, It works perfectly, but I want to understand it first if someone can please explain.(For the thresh and radius variables, I changed their values so It can work with my image).</p>
  
  <pre><code>thresh = 0.000999;
  radius = 1;
  sze = 2*radius + 1;                   % Size of dilation mask
  mx = ordfilt2(cim, sze^2, ones(sze));      % Grey-scale dilate
  
  % Make mask to exclude points on borders
  bordermask = zeros(size(cim));
  bordermask(radius+1:end-radius, radius+1:end-radius) = 1;
  
  % Find maxima, threshold, and apply bordermask
  cimmx = (cim==mx) &amp; (cim&gt;thresh) &amp; bordermask;
  [r, c] = find(cimmx);     % Return coordinates of corners
  
  figure, imshow(im),
  hold on;
  plot(c, r, '+');
  hold off;
  </code></pre>