Image Edge Detection using Sobel Operator
Afficher commentaires plus anciens
I am working on an assignment where I have to detect image edge using Sobel operator. It was stated that the output image must be uint8 format and has two fewer rows and columns than the input one, since the pixels in first and last columns and rows do not have enough neughbors for the required computation. I am struggling in the last part as I get same input and ouput size. I would apperciate your help and suggestions. I have attached my code for your reference.
function [edge] = edgy(cc)
cc = double(cc);
H = size(cc,1);
W = size(cc,2);
edge = cc;
sx = [-1 0 1;-2 0 2;-1 0 1];
sy = [1 2 1;0 0 0;-1 -2 -1];
for i = 2 : H-1
for j = 2 : W-1
A = cc(i - 1 : i + 1, j - 1 : j + 1);
a = (sum(sx .* A));
x = sum(a);
b = (sum(sy .* A));
y = sum(b);
pixValue =sqrt(x.^2+ y.^2);
edge(i, j) = pixValue;
end
end
edge = uint8(edge);
end
2 commentaires
João Pedro de Freitas Coelho
le 20 Oct 2020
function edge = edgy(figure)
cc = double(figure);
sx = [-1 0 1; -2 0 2; -1 0 1];
sy = [1 2 1; 0 0 0; -1 -2 -1];
B = cc;
for ii = 2:(size(B,1)-1)
for jj = 2:(size(B,2)-1)
A = cc((ii-1):(ii+1),(jj-1):(jj+1));
x = sx.*A;
x = sum(sum(x));
y = sy.*A;
y = sum(sum(y));
pixValue = uint8(sqrt(x.^2 + y.^2));
B(ii,jj) = pixValue;
end
end
B = uint8(B);
edge = B(2:end-1,2:end-1);
end
Osama Ahmed
le 2 Nov 2020
Réponses (0)
Catégories
En savoir plus sur Object Analysis dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!