Lets Learn together... Happy Reading

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

Recent Posts

Sobel edge detection

         The gradient of the image is calculated for each pixel position in the image.






























The procedure and the MATLAB  code for sobel edge detection without using MATLAB built-in function:


































MATLAB CODE:


A=imread('peppers.png');
B=rgb2gray(A);

C=double(B);


for i=1:size(C,1)-2
    for j=1:size(C,2)-2
        %Sobel mask for x-direction:
        Gx=((2*C(i+2,j+1)+C(i+2,j)+C(i+2,j+2))-(2*C(i,j+1)+C(i,j)+C(i,j+2)));
        %Sobel mask for y-direction:
        Gy=((2*C(i+1,j+2)+C(i,j+2)+C(i+2,j+2))-(2*C(i+1,j)+C(i,j)+C(i+2,j)));
     
        %The gradient of the image
        %B(i,j)=abs(Gx)+abs(Gy);
        B(i,j)=sqrt(Gx.^2+Gy.^2);
     
    end
end
figure,imshow(B); title('Sobel gradient');
Sobel Gradient

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

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












Edge detected Image



Edge detected Image(Threshold value:35)
The edge detected image can be obtained from the sobel gradient by
using a threshold value.


  • If the sobel gradient values are lesser than the threshold value then replace it with the threshold value.
    if f < threshold value then
    f = threshold value.

























To avoid complex computation, the gradient can also be computed using the formula:




The Image obtained from computing X-direction derivative:













The Image obtained from computing Y-direction derivative:



like button Like "IMAGE PROCESSING" page

9 comments:

Mukesh Mann said... Reply to comment

why did you substract 2 in the loops
for i=1:size(C,1)-2
for j=1:size(C,2)-2
????

Aaron Angel said... Reply to comment

@Mukesh Mann
From every (i,j)th position a 3x3 window is formed. On subtracting 2, the index out of bounds is avoided.

Tom said... Reply to comment

Hello, why are the results smaller than the original images? I tried to find it out but I couldn't. Or is it because of the sobel procedure itself? But I couldn't find any reference for this.

Sindhu Shenoy said... Reply to comment

Can you help me write point processing functions in matlab without using built-in functions???

Shahnewaz Siddiquee said... Reply to comment

How can i design a highpass filter for reducing noise from an image in Matlab without using image processing toolbox?
can anybody help?

Vignesh said... Reply to comment

Shahnewz- depends on what type of noise u wanna remove... if u wanna get rid of high freq noise then u gotta apply fourier transform and remove high frequency components.

vishal said... Reply to comment

for i=1:size(C,1)-2
for j=1:size(C,2)-2
%Sobel mask for x-direction:
Gx=((2*C(i+2,j+1)+C(i+2,j)+C(i+2,j+2))-(2*C(i,j+1)+C(i,j)+C(i,j+2)));
%Sobel mask for y-direction:
Gy=((2*C(i+1,j+2)+C(i,j+2)+C(i+2,j+2))-(2*C(i+1,j)+C(i,j)+C(i+2,j)));
sir i'm not able to understand dis part.can u explain it with example?
suppose C is 3x3 size array then what could be value of j.

Aaron Angel said... Reply to comment

@vishal

Contact me through mail. Will try to explain it with an example.

Jorge said... Reply to comment

please explain to all us

Enjoyed Reading? Share Your Views

Previous Post Next Post Home
Related Posts Plugin for WordPress, Blogger...
Twitter Bird Gadget Google ping Hypersmash.com