Monday, August 2, 2010

Sobel Edge Detection

clear all; close all; clc;
I = imread('lena.gif');
%I = rgb2gray(I);
I = im2double(I);
h = [-1 -2 -1;0 0 0;1 2 1]; % Horizontal Mask
h1 = [-1 0 1;-2 0 2;-1 0 1]; % Vertical Mask
h2 = [0 1 2;-1 0 1;-2 -1 0]; % -45 Degree
h3 = [-2 -1 0;-1 0 1;0 1 2]; % 45 Degree
f1 = imfilter(I,h,'replicate');
f2 = imfilter(I,h1,'replicate');
f3 = imfilter(I,h2,'replicate');
f4 = imfilter(I,h3,'replicate');
figure(1),imshow(I),title('Original Image');
figure(2);
subplot(2,2,1),imshow(f1),title('Horizontal Edge');
subplot(2,2,2),imshow(f2),title('Vertical Edge');
subplot(2,2,3),imshow(f3),title('-45 Degree Edge');
subplot(2,2,4),imshow(f4),title('45 Degree Edge');

No comments: