Image Edge Detection using Sobel Operator

6 ビュー (過去 30 日間)
Osama Ahmed
Osama Ahmed 2020 年 10 月 13 日
コメント済み: Osama Ahmed 2020 年 11 月 2 日
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 件のコメント
João Pedro de Freitas Coelho
João Pedro de Freitas Coelho 2020 年 10 月 20 日
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
Osama Ahmed 2020 年 11 月 2 日
Thank you very much João

サインインしてコメントする。

回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by