MATLAB CODES - FFT Image , Low pass Filtered Image , Band Pass Filtered Image

clc
close all
clear all

% Read the image, resize it to 256 x 256
% Convert it to grey image and display it

mygrayimg = imread('dog.tif');
mygrayimg = imresize(rgb2gray(mygrayimg),[256 256]);
subplot(2,2,1);
imshow(mygrayimg),title('Original Image');

% Find FFT
% Use the command fft2() to get FFT of the image
% The log scale of FFT image is displayed

myfftimage = fft2(mygrayimg);

% Take logarithmic scale for display

tmp = abs(myfftimage);
mylogimg = log(1+tmp);

subplot(2,2,2);
imshow(mat2gray(mylogimg));
title('FFT Image');

% Find size
[M,N] = size(myfftimage);

% Create Filter array

% The cut off frequency 20 is used here

low = 62;
band1 = 15;
band2 = 60;

% create ideal high pass filter mask

% Create matrix of size equals original matrix

mylowpassmask = ones(M,N);
mybandpassmask = ones(M,N);

% Generate values for ideal high pass mask

for u = 1:M
   for v = 1:N
     
       tmp = ((u-(M+1))/2)^2 +(v-(N+1)/2)^2;
       raddist = round((sqrt(tmp)));
       disp(raddist)
     
       if raddist > low
       mylowpassmask(u,v) = 0;
       end
     
       if raddist > band2 || raddist < band1;
       mybandpassmask(u,v) = 0;
       end
   end
end

% Shift the spectrum to the centre
f1 = fftshift(mylowpassmask);
f3 = fftshift(mybandpassmask);

% Apply the filter H to the FFT of the Image
resimage1 = myfftimage.*f1;
resimage3 = myfftimage.*f3;


% Apply the Inverse FFT to the filtered image

% Display the low pass filtered image
r1 = abs(ifft2(resimage1));
subplot(2,2,3);
imshow(r1,[]),title('Low Pass filtered image');


% Display the band pass filtered image

r3 = abs(ifft2(resimage3));
subplot(2,2,4);
imshow(r3,[]),title('Band Pass filtered image');

MATLAB CODES - FFT Image , Low pass Filtered Image , Band Pass Filtered Image MATLAB CODES - FFT Image , Low pass Filtered Image , Band Pass Filtered Image Reviewed by Suresh Bojja on 9/11/2018 03:26:00 AM Rating: 5

Subjects & Labs

AC (6) ADS (2) ATMEL (6) AWP (5) C- Language (3) CAO (5) CDAC (1) Cloud Computing (1) CMC (6) CN (10) CONSERVATION & MANAGEMENT Complete Notes (1) Control Sys (2) CVSM (2) Data Analytics (1) DC (5) Digital System Design (3) DIP (17) DLD (10) DLD Lab Manual (1) DS (4) DSD&DICA (9) DSP (6) EDC (45) Electonic Components (2) Embedded (7) EMWTL (6) ENERGY AUDIT (1) Engg. Mechanics (2) Engg.Chemistry (11) Faculty Files (6) Faculty Labs (1) Fuzzy (3) II MID (1) Job Exam Papers (4) LICA (1) Linux OS (1) Materials (1) MATLAB (27) MCU IDE 8051 (1) MEMS (4) MPMC (57) MPMC LAB Manual (3) MTECH (6) MWE (2) OC (1) PDC (9) Projects (8) RADAR (1) Research (9) RVSP (3) SC (1) Softwares (1) SS (2) STLD (19) TCSS (1) TSSN (1) TV Engg (1) VHDL (4) VLSI (8) VLSI Lab manual (1) WCN (1) Wireless Commu. (1) WSN (2)
Theme images by sebastian-julian. Powered by Blogger.