tuttelikz

Corner detection Moravec Algorithm [+]

Oct 9th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.19 KB | None | 0 0
  1. %A = [1 2 3 4 5; 4 5 6 7 8 ; 7 8 9 10 11; 12 13 16 15 14; 6 4 2 3 5];
  2. %[n,m] = size(A);
  3. %mask1 = [1 1 1; 1 1 1; 1 1 1];
  4.  
  5. I = imread('squareImage.jpg');
  6. A = rgb2gray(I);
  7. [n,m] = size(A);
  8. figure(1)
  9. imshow(A);
  10. hold on
  11.  
  12. thresholdValue = 1;
  13.  
  14. for i = 3:n-2
  15.     for j = 3:m-2
  16.         minimalValues(i,j) = 0;
  17.     end
  18. end
  19.  
  20. for i = 3:n-2
  21.     for j = 3:m-2
  22.         stationaryMatrix = [A(i-1,j-1) A(i-1,j) A(i-1,j+1); A(i,j-1) A(i,j) A(i,j+1); A(i+1,j-1) A(i+1,j) A(i+1,j+1)];
  23.        
  24.         movingMatrix(:,:,1) = [A(i-2,j-2) A(i-2,j-1) A(i-2,j); A(i-1,j-2) A(i-1,j-1) A(i-1,j); A(i,j-2) A(i,j-1) A(i,j)];
  25.         movingMatrix(:,:,2) = [A(i-2,j-1) A(i-2,j) A(i-2,j+1); A(i-1,j-1) A(i-1,j) A(i-1,j+1); A(i,j-1) A(i,j) A(i,j+1)];
  26.         movingMatrix(:,:,3) = [A(i-2,j) A(i-2,j+1) A(i-2,j+2); A(i-1,j) A(i-1,j+1) A(i-1,j+2); A(i,j) A(i,j+1) A(i,j+2)];
  27.         movingMatrix(:,:,4) = [A(i-1,j-2) A(i-1,j-1) A(i-1,j); A(i,j-2) A(i,j-1) A(i,j); A(i+1,j-2) A(i+1,j-1) A(i+1,j)];
  28.         movingMatrix(:,:,5) = [A(i-1,j) A(i-1,j+1) A(i-1,j+2); A(i,j) A(i,j+1) A(i,j+2); A(i+1,j) A(i+1,j+1) A(i+1,j+2)];
  29.         movingMatrix(:,:,6) = [A(i,j-2) A(i,j-1) A(i,j); A(i+1,j-2) A(i+1,j+1) A(i+1,j); A(i+2,j-2) A(i+2,j-1) A(i+2,j)];
  30.         movingMatrix(:,:,7) = [A(i,j-1) A(i,j) A(i,j+1); A(i+1,j-1) A(i+1,j) A(i+1,j+1); A(i+2,j-1) A(i+2,j) A(i+2,j+1)];
  31.         movingMatrix(:,:,8) = [A(i,j) A(i,j+1) A(i,j+2); A(i+1,j) A(i+1,j+1) A(i+1,j+2); A(i+2,j) A(i+2,j+1) A(i+2,j+2)];
  32.        
  33.         for page = 1:8
  34.            someCost(i,j,page) = 0;
  35.         end
  36.         minCost(i,j) = 1/0;
  37.        
  38.         for page = 1:8
  39.             for x = 1:3
  40.                 for y = 1:3
  41.                     someCost(i,j,page) = someCost(i,j,page) + (movingMatrix(x,y,page) - stationaryMatrix(x,y))^2;
  42.                 end
  43.             end
  44.         end
  45.        
  46.         for page = 1:8
  47.             if someCost(i,j,page) <= minCost(i,j)
  48.                 minCost(i,j) = someCost(i,j,page);
  49.             end
  50.         end
  51.        
  52.         if minCost(i,j) <= thresholdValue
  53.             cornerMap(i,j) = 0;
  54.         else
  55.             cornerMap(i,j) = minCost(i,j);
  56.             plot(i,j,'b.','MarkerSize',20);
  57.         end
  58.     end
  59. end
  60. hold off
Advertisement
Add Comment
Please, Sign In to add comment