Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- img = double (imread ('berndsface.png'));
- folder = 'C:\Users\HP\Documents\Laboratory Matlab\Laboratory 25\';
- h = [1, 0; 0, -1];
- filteredImg1 = imfilter (img, h', 'replicate');
- filteredImg1 = log (abs (filteredImg1) + 1 );
- filteredImg1 = filteredImg1 /max(filteredImg1 (:));
- h = [0, 1; -1, 0];
- filteredImg2 = double (imfilter (img, h, 'replicate'));
- filteredImg2 = log (abs (filteredImg2) + 1 );
- filteredImg2 = filteredImg1 /max (filteredImg2 (:));
- figure(5); clf;
- subplot (2, 4, 1), imshow (uint8 (img)); title ('Original');
- subplot (2, 4, 2), imshow (filteredImg1); title ('Roberts Horizontal');
- subplot (2, 4, 3), imshow (filteredImg2); title ('Roberts Anti- Diagonal');
- imwrite (filteredImg1,strcat(folder, 'Roberts_face_verticall.png'));
- imwrite (filteredImg2,strcat(folder, 'Roberts_face_horizontal.png'));
- % Roberts
- % Apply Roberts filter in two directions
- img = double (imread ('berndsface.png'));
- h = [1, 0; 0, -1];
- filteredImg1 = imfilter (img, h', 'replicate');
- h = [ 0, 1; -1, 0];
- filteredImg2 = double (imfilter (img, h, 'replicate'));
- % Threshold based on edge magnitude response
- edgeSum = filteredImg1 .^2 + filteredImg2 .^2;
- logEdgeSum = log (edgeSum + 1);
- logEdgeSum = logEdgeSum / max (logEdgeSum (:));
- bwEdge1 = edgeSum > 100;
- bwEdge2 = edgeSum > 500;
- bwEdge3 = edgeSum > 800;
- % Show and save images
- subplot (2, 4, 5), imshow (logEdgeSum); title ('Edge Magnitude');
- subplot (2, 4, 6), imshow (bwEdge1); title ('Magnitude > 100');
- subplot (2, 4, 7), imshow (bwEdge2); title ('Magnitude > 500');
- subplot (2, 4, 8), imshow (bwEdge3); title ('Magnitude > 800');
- imwrite (logEdgeSum,strcat(folder, 'Roberts_face_logEdgeSum.png'));
- imwrite (bwEdge1,strcat(folder, 'Roberts_face_bwEdge1.png'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement