edge detection using sobel operator
Mostrar comentarios más antiguos
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 comentarios
Akshay Gore
el 7 de Dic. de 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
el 14 de Dic. de 2016
Editada: Nenad Bozinovic
el 14 de Dic. de 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
el 2 de Oct. de 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?
Respuesta aceptada
Más respuestas (1)
chitresh
el 7 de Dic. de 2013
3 votos
I = imread('image_file');
BW1 = edge(I,'sobel');
imshow(BW1);
Categorías
Más información sobre Object Analysis en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!