IMAGE PROCESSING

" Two roads diverged in a wood, and I,
I took the one less traveled by,
And that has made all the difference "-Robert Frost

Sobel Edge Detection - Part 2

In Edge Detection- fundamentals, we have seen how the first and second order derivatives are used in finding the edge strength. Now lets see another version of sobel edge detection.

Basic Steps followed in Sobel Edge Detection:

1.       Obtain the gradient of the image.
2.       Find the magnitude

SOBEL EDGE DETECTION USING ‘edge’ FUNCTION:

%Input Image

%Image obtained using MATLAB function 'edge'
[E,th]=edge(A,'sobel','nothinning');
figure,imshow(E);title('Image obtained using MATLAB function')

Edge Detection without using the 'edge' function:

MATLAB CODE:

%Input Image

%Preallocate the matrices with zeros
I=zeros(size(A));

F1=[-1 0 1;-2 0 2; -1 0 1];
F2=[-1 -2 -1;0 0 0; 1 2 1];

A=double(A);

for i=1:size(A,1)-2
for j=1:size(A,2)-2
Gx=sum(sum(F1.*A(i:i+2,j:j+2)));
Gy=sum(sum(F2.*A(i:i+2,j:j+2)));

%Magnitude of vector
I(i+1,j+1)=sqrt(Gx.^2+Gy.^2);

end
end

I=uint8(I);
figure,imshow(I);title('Filtered Image');

%Define a threshold value
Thresh=210;
B=max(I,Thresh);
B(B==round(Thresh))=0;

B=im2bw(B);
figure,imshow(B);title('Edge detected Image');

EXPLANATION:

2.       Convert the image to double
3.       Use the mask F1 for x direction and F2 for y direction and obtain the gradient of the image.
4.       Find the magnitude of the vector.
5.       Since we need 3x3 image pixels, the border pixels are not considered, and so starting from the pixel (2, 2) the edge detection process starts.
%Magnitude of vector
I(i+1,j+1)=sqrt(Gx.^2+Gy.^2);
When i=1 and j =1, then Image I pixel position will be I(2,2).Thus we are not considering the borders.
Example:

In the for loop 2 is subtracted.
"
for i=1:size(A,1)-2
for j=1:size(A,2)-2 "
The filter mask is 3x3, so the last position to be processed in our example is I(3,3).And normally it will be I(size(A,1)-2,size(A,2)-2). Thus the borders are left.

Example :

6.       Threshold the image
7.       Display the logical image

1. Sobel masks perform better noise suppression.

2. Image smoothing

1.       Diagonal direction points are not preserved always.

Like "IMAGE PROCESSING" page