Advertisement
bkit4s0

harris.m bản nháp

Dec 28th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.53 KB | None | 0 0
  1. function [cim, r, c] = harris(im, sigma, thresh, radius)
  2. % Arguments:  
  3. %            im     - image to be processed.
  4. %            sigma  - standard deviation of smoothing Gaussian. Typical
  5. %                     values to use might be 1-3.
  6. %            thresh - threshold (optional). Try a value ~50
  7. %            radius - radius of region considered in non-maximal
  8. %                     suppression (optional). Typical values to use might
  9. %                     be 1-3.
  10. %
  11. % Returns:
  12. %            cim    - binary image marking corners.
  13. %            r      - row coordinates of corner points.
  14. %            c      - column coordinates of corner points.
  15. error(nargchk(2,5,nargin));    
  16. %dx = [-1 0 1; -1 0 1; -1 0 1];
  17. dx = fspecial('sobel');
  18. dy = dx';    
  19. Ix = conv2(im, dx, 'same');
  20. Iy = conv2(im, dy, 'same');    
  21. g = fspecial('gaussian',max(1,fix(6*sigma)), sigma);    
  22. Ix2 = conv2(Ix.^2, g, 'same');
  23. Iy2 = conv2(Iy.^2, g, 'same');
  24. Ixy = conv2(Ix.*Iy, g, 'same');
  25. %-----------
  26. cim = (Ix2.*Iy2 - Ixy.^2)./(Ix2 + Iy2 + eps);
  27. if nargin > 2
  28. sze = 2*radius+1;                
  29. mx = ordfilt2(cim,sze^2,ones(sze));
  30. cim = (cim==mx)&(cim>thresh);       % Find maxima
  31. [r,c] = find(cim);    
  32. end
  33. %-----------
  34. max = 0;
  35. [sy, sx] = size(Ix2);
  36. K = zeros(sy, sx);
  37. for i = 1:sx,
  38.     for j = 1:sy,
  39.         M = [Ix2(j,i), Ixy(j,i)
  40.             Ixy(j,i), Iy2(j,i)];
  41.         R(j,i) = det(M) - k*(trace(M))^2;
  42.         if R(j,i) > max,
  43.             max = R(j,i);
  44.         end
  45.     end
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement