Lab 4
Sobel operators
%display image
clc ; clear
a=imread('2.jpg');
x=rgb2gray(a);
f=padarray(x ,[1 1],'replicate','both');
[M,N]=size(f);
for x=2:M-1
for y = 2:N-1
Gx1=f(x+1,y-1)+2*f(x+1,y)+f(x+1,y+1);
Gx2=f(x-1,y-1)+2*f(x-1,y)+f(x-1,y+1);
Gx(x-1,y-1)=abs(Gx1-Gx2);
Gy1=f(x-1,y-1)+2*f(x,y+1)+f(x+1,y+1);
Gy2=f(x+1,y-1)+2*f(x,y-1)+f(x+1,y+1);
Gy(x-1,y-1)=abs(Gy1-Gy2);
G(x-1,y-1)=Gx(x-1,y-1)+Gy(x-1,y-1);
end
end
figure(2)
imshow (G)