Skip to content

Commit

Permalink
Add Edge Detection Filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Showndarya committed May 25, 2018
1 parent 0ac10b5 commit 05e4535
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 1 deletion.
25 changes: 25 additions & 0 deletions Edge_Detection_Filters/Laplacian.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pkg load image;

img = rgb2gray(imread("deer1.jpg"));
subplot(1,2,1);
imshow(img);
title('Original Image');

img = double(img);
h = [-1,2,-1;2,-4,2;-1,2,-1];
oimg = zeros(rows(img),columns(img));

for i=2:rows(img)-1
for j=2:columns(img)-1
a =img(i-1,j-1)*h(1) + img(i-1,j)*h(2) + img(i-1,j+1)*h(3) + img(i,j-1)*h(4) + img(i,j)*h(5) + img(i,j+1)*h(6) + img(i+1,j-1)*h(7) + img(i+1,j)*h(8) + img(i+1,j+1)*h(9); %sum(sum(img(i-1:i+1,j-1:j+1) .* h));
if(a<0)
oimg(i,j) = 0;
else
oimg(i,j) = a;
end
end
end

subplot(1,2,2);
imshow(uint8(oimg));
title('On Applying Laplacian High Pass Filter');
25 changes: 25 additions & 0 deletions Edge_Detection_Filters/Prewitt.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pkg load image;

img = rgb2gray(imread("deer1.jpg"));
subplot(1,2,1);
imshow(img);
title('Original Image');

img = double(img);
h = [-2,-1,0;-1,0,1;0,1,2];
oimg = zeros(rows(img),columns(img));

for i=2:rows(img)-1
for j=2:columns(img)-1
a = sum(sum(img(i-1:i+1,j-1:j+1) .* h));
if(a<0)
oimg(i,j) = 0;
else
oimg(i,j) = a;
end
end
end

subplot(1,2,2);
imshow(uint8(oimg));
title('On Applying Prewitt High Pass Filter');
38 changes: 38 additions & 0 deletions Edge_Detection_Filters/Robert.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
pkg load image;

img = rgb2gray(imread("deer1.jpg"));
subplot(1,2,1);
imshow(img);
title('Original Image');

img = double(img);
r1 = [1,0;0,-1];
oimg = zeros(rows(img),columns(img));

for i=1:rows(img)-1
for j=1:columns(img)-1
a = img(i,j)*r1(1) + img(i,j+1)*r1(2) + img(i+1,j)*r1(3) + img(i+1,j+1)*r1(4);
if(a<0)
oimg(i,j) = 0;
else
oimg(i,j) = a;
end
end
end

r2 = [0,1;-1,0];

for i=1:rows(img)-1
for j=1:columns(img)-1
a = img(i,j)*r2(1) + img(i,j+1)*r2(2) + img(i+1,j)*r2(3) + img(i+1,j+1)*r2(4);
if(a<0)
oimg(i,j+1) = oimg(i,j+1) + 0;
else
oimg(i,j+1) = oimg(i,j+1) + a;
end
end
end

subplot(1,2,2);
imshow(uint8(oimg));
title('On Applying Robert High Pass Filter');
25 changes: 25 additions & 0 deletions Edge_Detection_Filters/Sobel.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pkg load image;

img = rgb2gray(imread("deer1.jpg"));
subplot(1,2,1);
imshow(img);
title('Original Image');

img = double(img);
h = [-2,-2,0;-2,0,2;0,2,2];
oimg = zeros(rows(img),columns(img));

for i=2:rows(img)-1
for j=2:columns(img)-1
a = sum(sum(img(i-1:i+1,j-1:j+1) .* h));
if(a<0)
oimg(i,j) = 0;
else
oimg(i,j) = a;
end
end
end

subplot(1,2,2);
imshow(uint8(oimg));
title('On Applying Sobel High Pass Filter');
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ This repository contains some of the programs written for the course **Digital S
* [Point Processing techniques in Spatial domain](./Point_Processing_Techniques)
* [Contrast Stretching and Histogram Equalization](./Contrast_Stretching_and_Histogram_Equalization)
* [Filters](./Filters)

* [Edge Detection Filters](./Edge_Detection_Filters)

0 comments on commit 05e4535

Please sign in to comment.