Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %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];
- %[n,m] = size(A);
- %mask1 = [1 1 1; 1 1 1; 1 1 1];
- I = imread('squareImage.jpg');
- A = rgb2gray(I);
- [n,m] = size(A);
- figure(1)
- imshow(A);
- hold on
- thresholdValue = 1;
- for i = 3:n-2
- for j = 3:m-2
- minimalValues(i,j) = 0;
- end
- end
- for i = 3:n-2
- for j = 3:m-2
- 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)];
- 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)];
- 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)];
- 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)];
- 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)];
- 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)];
- 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)];
- 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)];
- 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)];
- for page = 1:8
- someCost(i,j,page) = 0;
- end
- minCost(i,j) = 1/0;
- for page = 1:8
- for x = 1:3
- for y = 1:3
- someCost(i,j,page) = someCost(i,j,page) + (movingMatrix(x,y,page) - stationaryMatrix(x,y))^2;
- end
- end
- end
- for page = 1:8
- if someCost(i,j,page) <= minCost(i,j)
- minCost(i,j) = someCost(i,j,page);
- end
- end
- if minCost(i,j) <= thresholdValue
- cornerMap(i,j) = 0;
- else
- cornerMap(i,j) = minCost(i,j);
- plot(i,j,'b.','MarkerSize',20);
- end
- end
- end
- hold off
Advertisement
Add Comment
Please, Sign In to add comment