Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. img = double (imread ('berndsface.png'));
  2. folder = 'C:\Users\HP\Documents\Laboratory Matlab\Laboratory 25\';
  3. h = [1, 0; 0, -1];
  4. filteredImg1 = imfilter (img, h', 'replicate');
  5. filteredImg1 = log (abs (filteredImg1) + 1 );
  6. filteredImg1 = filteredImg1 /max(filteredImg1 (:));
  7.  
  8. h = [0, 1; -1, 0];
  9. filteredImg2 = double (imfilter (img, h, 'replicate'));
  10. filteredImg2 = log (abs (filteredImg2) + 1 );
  11. filteredImg2 = filteredImg1 /max (filteredImg2 (:));
  12.  
  13. figure(5); clf;
  14. subplot (2, 4, 1), imshow (uint8 (img)); title ('Original');
  15. subplot (2, 4, 2), imshow (filteredImg1); title ('Roberts Horizontal');
  16. subplot (2, 4, 3), imshow (filteredImg2); title ('Roberts Anti- Diagonal');
  17. imwrite (filteredImg1,strcat(folder, 'Roberts_face_verticall.png'));
  18. imwrite (filteredImg2,strcat(folder, 'Roberts_face_horizontal.png'));
  19.  
  20. % Roberts
  21. % Apply Roberts filter in two directions
  22.  
  23. img = double (imread ('berndsface.png'));
  24. h = [1, 0; 0, -1];
  25. filteredImg1 = imfilter (img, h', 'replicate');
  26. h = [ 0, 1; -1, 0];
  27. filteredImg2 = double (imfilter (img, h, 'replicate'));
  28.  
  29. % Threshold based on edge magnitude response
  30.  
  31. edgeSum = filteredImg1 .^2 + filteredImg2 .^2;
  32. logEdgeSum = log (edgeSum + 1);
  33. logEdgeSum = logEdgeSum / max (logEdgeSum (:));
  34. bwEdge1 = edgeSum > 100;
  35. bwEdge2 = edgeSum > 500;
  36. bwEdge3 = edgeSum > 800;
  37.  
  38. % Show and save images
  39. subplot (2, 4, 5), imshow (logEdgeSum); title ('Edge Magnitude');
  40. subplot (2, 4, 6), imshow (bwEdge1); title ('Magnitude > 100');
  41. subplot (2, 4, 7), imshow (bwEdge2); title ('Magnitude > 500');
  42. subplot (2, 4, 8), imshow (bwEdge3); title ('Magnitude > 800');
  43. imwrite (logEdgeSum,strcat(folder, 'Roberts_face_logEdgeSum.png'));
  44. imwrite (bwEdge1,strcat(folder, 'Roberts_face_bwEdge1.png'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement