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!