edge detection using sobel operator
이전 댓글 표시
my question is related to edge detection using sobel operator. I am doing my project related to this subject on FPGA so i want to see that what will be the result in matlab can u tell me how to do edge detection using sobel oerator in matlab. Thank you
댓글 수: 3
Akshay Gore
2013년 12월 7일
function [ lenaOutput] = sobel(X)
%X input color image
X= double(X); height = size(X, 1); width = size(X, 2); channel = size(X, 3);
lenaOutput = X;
Gx = [1 +2 +1; 0 0 0; -1 -2 -1]; Gy = Gx';
for i = 2 : height-1
for j = 2 : width-1
for k = 1 : channel
tempLena = X(i - 1 : i + 1, j - 1 : j + 1, k);
a=(sum(Gx.* tempLena));
x = sum(a);
b= (sum(Gy.* tempLena));
y = sum(b);
pixValue =sqrt(x.^2+ y.^2);
% pixValue =(x-y);
lenaOutput(i, j, k) = pixValue;
end
end
end
lenaOutput = uint8(lenaOutput); figure; imshow(abs(lenaOutput),[]); title(' Sobel Edge Detection');
Nenad Bozinovic
2016년 12월 14일
편집: Nenad Bozinovic
2016년 12월 14일
Above works but it's slow (1.218 seconds for my image). Here is a faster way:
Gx = [1 +2 +1; 0 0 0; -1 -2 -1]; Gy = Gx';
tic
temp_x = conv2(X, Gx, 'same');
temp_y = conv2(X, Gy, 'same');
lenaOutput = sqrt(temp_x.^2 + temp_y.^2);
toc
Elapsed time is 0.005787 seconds.
fzhmktr
2019년 10월 2일
Hi nenad,
I try your code and I didnt get the same result as Akshay code. Your code resulting in matrix dimension while Akshay code in single value. Am I making mistake?
채택된 답변
추가 답변 (1개)
chitresh
2013년 12월 7일
3 개 추천
I = imread('image_file');
BW1 = edge(I,'sobel');
imshow(BW1);
카테고리
도움말 센터 및 File Exchange에서 Object Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!