Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Sobel
- % Apply Sobel in vertical and horizontal directions
- img = double (imread ('berndsface.png'));
- folder = 'C:\Users\HP\Documents\Laboratory Matlab\Laboratory 25\';
- h = fspecial ('sobel');
- filteredImg1 = imfilter (img, h', 'replicate');
- 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 > 1600; % (4/3) ^2 times the value for Prewitt
- bwEdge2 = edgeSum > 8000;
- bwEdge3 = edgeSum > 12800;
- % Show and save images
- figure(4), clf;
- subplot (2, 2, 1), imshow (logEdgeSum); title ('Edge Magnitude');
- subplot (2, 2, 2), imshow (bwEdge1); title ('Magnitude > 1600');
- subplot (2, 2, 3), imshow (bwEdge2); title ('Magnitude > 8000');
- subplot (2, 2, 4), imshow (bwEdge3); title ('Magnitude > 128000');
- imwrite (logEdgeSum,strcat(folder, 'Sobel_face_logEdgeSum.png'));
- imwrite (bwEdge1,strcat(folder, 'Sobel_face_bwEdge1.png'));
- imwrite (bwEdge2,strcat(folder, 'Sobel_face_bwEdge2.png'));
- imwrite (bwEdge3,strcat(folder, 'Sobel_face_beEdge3.png'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement