Edge detection using sobel operator
1 次查看(过去 30 天)
显示 更早的评论
Can anyone point out what's causing the error in the code below?
Below is the code for detecting edge using sobel operator.
Thank you for your time and effort in advance.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/374931/image.png)
function output = edgy(a)
a = double(a);
[row col] = size(a);
My = [-1 -2 -1;0 0 0;1 2 1];
Mx =[-1 0 1;-2 0 2;-1 0 1];
a3 =zeros(row,col);
for i =1:row-2
for j=1:col-2
Gx = sum(sum(Mx.*a(i:i+2, j:j+2)));
Gy = sum(sum(My.*a(i:i+2, j:j+2)));
filtered_image(i,j) = sqrt(Gx.^2 + Gy.^2);
end
end
filtered_image = uint8(filtered_image);
thresholdvalue =100;
output = max(filtered_image,thresholdvalue);
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/374946/image.png)
6 个评论
J. Alex Lee
2020-10-9
Ah ok. If you have access to full matlab (image processing toolbox), look into imfilter() as Image Analyst suggests, but also imgradientxy(). Then later you can look into conv2().
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!