Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save agaikwad123/9bef035cffb7ac7342ff51de25369805 to your computer and use it in GitHub Desktop.
Save agaikwad123/9bef035cffb7ac7342ff51de25369805 to your computer and use it in GitHub Desktop.
Clc
I=imread('cameraman.tif');
[m n]=size(I);
a=im2double(I);
for i=1:m-2
for j=1:n-2
v(i,j) = [a(i,j) + a(i,j+1) + a(i,j+2) + a(i+1,j) + a(i+1,j+1) + a(i+1,j+2) + a(i+2,j) + a(i+2,j+1) + a(i+2,j+2)]./9; %smoothing filter
x(i,j) = [0*a(i,j) + 1*a(i,j+1) + 0*a(i,j+2) + 1*a(i+1,j) + -4*a(i+1,j+1) + 1*a(i+1,j+2) + 0*a(i+2,j) + 1*a(i+2,j+1) + 0*a(i+2,j+2)]; %high pass filter
w(i,j) = [1*a(i,j) + 1*a(i,j+1) + 1*a(i,j+2) + 1*a(i+1,j) + -8*a(i+1,j+1) + 1*a(i+1,j+2) + 1*a(i+2,j) + 1*a(i+2,j+1) + 1*a(i+2,j+2)]; %high boost filter
array = [a(i,j),a(i,j+1),a(i,j+2),a(i+1,j),a(i+1,j+1),a(i+1,j+2),a(i+2,j),a(i+2,j+1),a(i+2,j+2)];
arr(i,j)=median(array); %median filter
y(i,j)=min(array); %minimum filter
z(i,j)=max(array); %maximum filter
end;
end;
figure;imshow(I);
title('Original image');
figure;imshow(v);
title('Image after Low pass filtering (smoothing)');
figure;imshow(x);
title('Image after high pass filtering');
figure;imshow(w);
title('Image after high boost filtering');
figure;imshow(arr);
title('Image after median filtering');
figure;imshow(y);
title('Image after minimum filtering');
figure;imshow(z);
title('Image after maximum filtering');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment