You are on page 1of 8

# Digital Image Processing

Low pass, High pass and Band pass filtering of a given Image

## LOW PASS FILTERING Code:

clc; clear all; thresh=100; im1=imread('gandhi.jpg'); im2=rgb2gray(im1); im=fft(im2); im3=im; [r,c]=size(im); d0=thresh; h=zeros(r,c);

--------------------------> Read the image --------------------------> Converting true colour image to grayscale image --------------------------> Converting image to frequency domain and determining its size

for i=1:r ---------------------------> Code for generating low for j=1:c pass filter function d(i,j)= sqrt( (i-(r/2))^2 + (j-(c/2))^2); end end for i=1:r for j=1:c h(i,j)= exp ( -( (d(i,j)^2)/(2*(d0^2)) ) ); end end for i=1:r for j=1:c res(i,j)=(h(i,j))*im(i,j); end end fres=ifft(res); subplot(2,2,1) imshow(im2,[ ]) title('Original image')` -------------------------> Multiplying every pixel of the image in frequency domain with the corresponding element of the filter function

## --------------------------> Finally taking the inverse fourier transform

Page

subplot(2,2,2) imshow(im3) title('Fourier spectrum of image') subplot(2,2,3) imshow(h,[ ]) title('Gaussian lowpass filter response') subplot(2,2,4) imshow(fres,[ ]) title('lowpass filtered image')

OUTPUT :

Page

## HIGH PASS FILTERING

Code:
clc; clear all; thresh=100; im1=imread('gandhi.jpg'); im2=rgb2gray(im1); im=fft(im2); im3=im; [r,c]=size(im); d0=thresh; h=zeros(r,c);

--------------------------> Read the image --------------------------> Converting true colour image to grayscale image --------------------------> Converting image to frequency domain and determining its size

for i=1:r ---------------------------> Code for generating high for j=1:c pass filter function d(i,j)= sqrt( (i-(r/2))^2 + (j-(c/2))^2); end end for i=1:r for j=1:c h(i,j)=1- exp ( -( (d(i,j)^2)/(2*(d0^2)) ) ); end end for i=1:r for j=1:c res(i,j)=(h(i,j))*im(i,j); end end fres=ifft(res); subplot(2,2,1) imshow(im2,[ ]) title('Original image')` -------------------------> Multiplying every pixel of the image in frequency domain with the corresponding element of the filter function

Page

## --------------------------> Finally taking the inverse fourier transform

subplot(2,2,2) imshow(im3) title('Fourier spectrum of image') subplot(2,2,3) imshow(h,[ ]) title('Gaussian highpass filter response') subplot(2,2,4) imshow(fres,[ ]) title('Highpass filtered image')

OUTPUT:

Page

## BAND PASS FILTERING Code:

clc; clear all; thresh=100; im1=imread('gandhi.jpg'); im2=rgb2gray(im1); im=fft(im2); im3=im; [r,c]=size(im); d0=thresh; h=zeros(r,c);

--------------------------> Read the image --------------------------> Converting true colour image to grayscale image --------------------------> Converting image to frequency domain and determining its size

for i=1:r ---------------------------> Code for generating band for j=1:c pass filter function d(i,j)= sqrt( (i-(r/2))^2 + (j-(c/2))^2); end end for i=1:r for j=1:c h1(i,j)=1-exp ( -( (d(i,j)^2)/(2*(d0^2)) ) ); h2(i,j)=exp ( -( (d(i,j)^2)/(2*(d1^2)) ) ); h3(i,j)=h1(i,j)+h2(i,j); end end for i=1:r -------------------------> Multiplying every pixel of the for j=1:c image in frequency domain res(i,j)=(h3(i,j))*im(i,j); with the corresponding end element of the filter function end fres=ifft(res); subplot(2,2,1) imshow(im2,[ ]) title('Original image')` --------------------------> Finally taking the inverse fourier transform
Page

subplot(2,2,2) imshow(im3) title('Fourier spectrum of image') subplot(2,2,3) imshow(h,[ ]) title('Gaussian bandpass filter response') subplot(2,2,4) imshow(fres,[ ]) title('bandpass filtered image')

OUTPUT:

Page

## OBSERVATIONS: 1. Lowpass Filtering:

Lowpass filter smoothens the image. By reducing the high-frequency components while preserving the low-frequency components, lowpass filtering reduces a large amount of noise at the expense of reducing a small amount of signal.

2. Highpass Filtering:
By highpass filtering image sharpness can be achieved. By increasing the sharpness finite details in the image can be obtained.This filter can also effectively extract the edges contained in an image.

3. Bandpass Filtering:
A bandpass attenuates very low and very high frequencies. Bandpass filtering can be used to enhance edges (suppressing low frequencies) while reducing the noise at the same time (attenuating high frequencies). In case of bandpass filtering there is always a trade-off between blurring and noise.
Page