clc
clear all
close all
A=imread('E:\teaching image processing\ppt.image\source\filter_soble.tif');
figure,imshow(A);
title('original image');
[m n]=size(A);
R=im2double(A);
B=zeros(m,n);
%% filter sobel in direction x
for i=2:m-1
for j=2:n-1
B(i,j)=(-2*R(i+1,j)+2*R(i-1,j)-R(i+1,j-1)-R(i+1,j+1)+R(i-1,j-1)+R(i-1,j+1));
end
end
figure,imshow( B);
title('filter sobel in direction x');
%% filter sobel in direction y
for k=2:m-1
for p=2:n-1
C(k,p)=(2*R(k,p+1)-2*R(k,p-1)-R(k+1,p-1)+R(k+1,p+1)-R(k-1,p-1)+R(k-1,p+1));
end
end
figure,imshow(C);
title('filter sobel in direction y');