Beruflich Dokumente
Kultur Dokumente
ASSIGNMENT
Make the program for edge linking to continue the sobel or prewitt operator method
on the last assignment.
PREFACE
Edge linking
Since in real images the edge detection does not produce a clean
set of edge points, some processing for obtaining the structure of the
edges is required. Ideally, edge detection techniques yield pixels lying
only on the boundaries between regions. In practice, this pixel set seldom
characterizes a boundary completely because of:
o Noise.
o Breaks in the boundary due to non-uniform illumination.
o Other effects that introduce spurious discontinuities.
Thus, edge detection algorithms are usually followed by linking and other
boundary detection procedures designed to assemble edge pixels into
meaningful boundaries.
Local processing:
Basic idea :
o Analyze the characteristics of pixels in a small neighborhood
(3x3, 5x5 etc) for every point (x,y) that has undergone edge
detection
o All points that are similar are linked, forming a boundary of
pixels that share some common property.
Below is the listing program for sobel operation method plus edge linking with
local processing.
SOURCE CODE
im = imread('pinkflower.jpg');
red = im(:,:,1);
green = im(:,:,2);
blue = im(:,:,3);
gs = (0.299*red)+(0.587*green)+(0.144*blue);
mat = double(gs);
[x y] = size(mat);
for i=2: x-2
for j=2: y-2
%_Sobel mask for x-direction
Gx = ((2*mat(i+2,j+1) + mat(i+2,j) + mat(i+2,j+2)) - (2*mat(i,j+1) + mat(i,j) +
mat(i,j+2)));
%_Sobel mask for x-direction
Gy = ((2*mat(i+1,j+2) + mat(i,j+2) + mat(i+2,j+2)) - (2*mat(i+1,j) + mat(i,j) +
mat(i+2,j)));
result(i,j) = sqrt(Gx.^2 + Gy.^2);
A(i,j) = atand(Gy/Gx);
h_gx(i,j) = Gx;
h_gy(i,j) = Gy;
end
end
result = uint8(result);
Thresh = 120;
Z = max(result,Thresh);
Z(Z==round(Thresh))=0;
Z = uint8(Z);
thres_a = 40;
thres_t = 15;
for m=2 : x-3
for n=2 : y-3
if(m>1 && m<x && n>1 && n<y)
if(abs((result(m+1,n) - result(m,n))) <= thres_t && abs((A(m+1,n) A(m,n))) < thres_a)
EL(m,n) = Z(m,n);
EL(m+1,n) = Z(m+1,n);
end
if(abs((result(m,n+1) - result(m,n))) <= thres_t && abs((A(m,n+1) A(m,n))) < thres_a)
EL(m,n) = Z(m,n);
EL(m,n+1) = Z(m,n+1);
end
if(abs((result(m+1,n+1) - result(m,n))) <= thres_t && abs((A(m+1,n+1) A(m,n))) < thres_a)
EL(m,n) = Z(m,n);
EL(m+1,n+1) = Z(m+1,n+1);
end
else
EL(m,n)=0;
end
end
end