edge detection using sobel operator
Afficher commentaires plus anciens
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 commentaires
Akshay Gore
le 7 Déc 2013
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
le 14 Déc 2016
Modifié(e) : Nenad Bozinovic
le 14 Déc 2016
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
le 2 Oct 2019
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?
Réponse acceptée
Plus de réponses (1)
chitresh
le 7 Déc 2013
3 votes
I = imread('image_file');
BW1 = edge(I,'sobel');
imshow(BW1);
Catégories
En savoir plus sur Object Analysis dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!