Edge detection: Difference between revisions

Content deleted Content added
Line 286:
Source:<ref>{{Cite web |date=2021-10-11 |title=Edge detection using Prewitt, Scharr and Sobel Operator |url=https://www.geeksforgeeks.org/edge-detection-using-prewitt-scharr-and-sobel-operator/ |access-date=2024-05-08 |website=GeeksforGeeks |language=en-US}}</ref>
 
=== Edge Detectiondetection using Prewitt Operatoroperator ===
<syntaxhighlight lang="matlab" line="1">
% MATLAB code for prewitt
% operator edge detection
k = imread("logo.png");
k = rgb2gray(k);
k1 = double(k);
p_msk = [-1 0 1; -1 0 1; -1 0 1];
kx = conv2(k1, p_msk, 'same');
ky = conv2(k1, p_msk', 'same');
ked = sqrt(kx.^2 + ky.^2);
 
% display the images.
Line 309:
% display the full edge detection.
imtool(abs(ked),[]);
 
</syntaxhighlight>
 
=== Edge Detectiondetection using Scharr Operatoroperator ===
<syntaxhighlight lang="matlab" line="1">
% Scharr operator -> edge detection
k = imread("logo.png");
k = rgb2gray(k);
k1 = double(k);
s_msk = [-3 0 3; -10 0 10; -3 0 3];
kx = conv2(k1, s_msk, 'same');
ky = conv2(k1, s_msk', 'same');
ked = sqrt(kx.^2 + ky.^2);
% display the images.
imtool(k,[]);
% display the edge detection along x-axis.
imtool(abs(kx), []);
% display the edge detection along y-axis.
imtool(abs(ky), []);
% display the full edge detection.
imtool(abs(ked), []);
 
</syntaxhighlight>
 
=== Edge DetectionDdtection using Sobel Operatoroperator ===
<syntaxhighlight lang="matlab" line="1">
% MATLAB code for Sobel operator
% edge detection
k = imread("logo.png");
k = rgb2gray(k);
k1 = double(k);
s_msk = [-1 0 1; -2 0 2; -1 0 1];
kx = conv2(k1, s_msk, 'same');
ky = conv2(k1, s_msk', 'same');
ked = sqrt(kx.^2 + ky.^2);
 
% display the images.
imtool(k,[]);
 
% display the edge detection along x-axis.
imtool(abs(kx), []);
 
% display the edge detection along y-axis.
imtool(abs(ky), []);
 
%display the full edge detection.
imtool(abs(ked),[]);
 
% display the full edge detection.
imtool(abs(ked), []);
</syntaxhighlight>