Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. %% Sobel
  2.  
  3. % Apply Sobel in vertical and horizontal directions
  4. img = double (imread ('berndsface.png'));
  5. folder = 'C:\Users\HP\Documents\Laboratory Matlab\Laboratory 25\';
  6. h = fspecial ('sobel');
  7. filteredImg1 = imfilter (img, h', 'replicate');
  8. filteredImg2 = double (imfilter (img, h, 'replicate'));
  9.  
  10. %Threshold based on edge magnitude response
  11. edgeSum = filteredImg1 .^2 + filteredImg2 .^2;
  12. logEdgeSum = log (edgeSum + 1);
  13. logEdgeSum = logEdgeSum / max (logEdgeSum (:));
  14. bwEdge1 = edgeSum > 1600; % (4/3) ^2 times the value for Prewitt
  15. bwEdge2 = edgeSum > 8000;
  16. bwEdge3 = edgeSum > 12800;
  17.  
  18. % Show and save images
  19. figure(4), clf;
  20. subplot (2, 2, 1), imshow (logEdgeSum); title ('Edge Magnitude');
  21. subplot (2, 2, 2), imshow (bwEdge1); title ('Magnitude > 1600');
  22. subplot (2, 2, 3), imshow (bwEdge2); title ('Magnitude > 8000');
  23. subplot (2, 2, 4), imshow (bwEdge3); title ('Magnitude > 128000');
  24. imwrite (logEdgeSum,strcat(folder, 'Sobel_face_logEdgeSum.png'));
  25. imwrite (bwEdge1,strcat(folder, 'Sobel_face_bwEdge1.png'));
  26. imwrite (bwEdge2,strcat(folder, 'Sobel_face_bwEdge2.png'));
  27. imwrite (bwEdge3,strcat(folder, 'Sobel_face_beEdge3.png'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement