Program for Sobel Operator edge detection using Matlab
SOBEL EDGE DETECTION
Standard Sobel
operators, for a 3×3 neighborhood, each simple central
gradient estimate is vector sum of a pair of orthogonal vectors. Each
orthogonal vector is a directional derivative estimate multiplied by a unit
vector specifying the derivative’s direction. The vector sum of these simple
gradient estimates amounts to a vector sum of the 8 directional derivative
vectors.
%Program
clear all;
clc;
aa=imread('D:\Edge.jpg');
a=rgb2gray(aa);
[row,col]=size(a);
w1=[-1 -2 -1;0 0 0;1 2 1];
w2=[-1 0 1;-2 0 2;-1 0 1];
for x=2:1:row-1;
for y=2:1:col-1;
a1(x,y)=w1(1)*a(x-1,y-1)+w1(2)*a(x-1,y)+w1(3)*a(x-1,y+1)+w1(4)*a(x,y-1)+w1(5)*a(x,y)+w1(6)*a(x,y+1)+w1(7)*a(x,y+1)+w1(3)*a(x+1,y-1)+w1(8)*a(x+1,y)+w1(9)*a(x+1,y+1);