Advertisement
bkit4s0

[Harris] source code stackoverflow

Dec 24th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.39 KB | None | 0 0
  1. clc;
  2. clear;
  3. close;
  4.  
  5. %grayImage = checkerboard(50);
  6. grayImage = imread('IMG_20141225_001413.jpg');
  7. grayImage = rgb2gray(grayImage);
  8. grayImage = im2double(grayImage);
  9. verticalMask = [-1 0 1;
  10.             -2 0 2;
  11.             -1 0 1]* 0.25;
  12. % Create a mask for deteting the horizontal edges
  13. horisontalMask = [-1 -2 -1;
  14.               0 0 0;
  15.               1 2 1]* 0.25;
  16. % Create a mask for Gaussian filter(is used to improve the result)
  17. gaussianFilter= fspecial('gaussian');
  18. K = 0.04; % The sensitivity factor used in the Harris detection algorithm (Used to detect sharp corners).
  19. % Get the gradient of the image [Ix,Iy], using the convulation function
  20. Ix = conv2(grayImage,verticalMask);
  21. Iy = conv2(grayImage,horisontalMask);
  22.  
  23. % get the input arguments of the harris formula
  24. Ix2 = Ix.* Ix; % get Ix to the power of two
  25. Iy2 = Iy.* Iy; % get Iy to the power of two
  26. Ixy = Ix .* Iy; %get the Ixy by multiply Ix and Iy
  27.  
  28. % Apply the gaussian filter to the the arguments
  29. Ix2 = conv2(Ix2,gaussianFilter);
  30. Iy2 = conv2(Iy2,gaussianFilter);
  31. Ixy = conv2(Ixy,gaussianFilter);
  32.  
  33. % Enetr the arguments into the formula
  34. C = (Ix2 .* Iy2) - (Ixy.^2) - K * ( Ix2 + Iy2 ).^ 2;
  35.  
  36. thresh = 0.000999;
  37. radius = 1;
  38.  
  39. % Find maxima, threshold, and apply bordermask
  40. cimmx = (C>thresh);
  41. [r, c] = find(cimmx);     % Return coordinates of corners
  42.  
  43. figure, imshow(grayImage);
  44. hold on;
  45. plot(c, r, '+');
  46. hold off;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement