Write Matlab code for the following: Load image ‘Balloon.tif’ and convert it int
ID: 3804726 • Letter: W
Question
Write Matlab code for the following:
Load image ‘Balloon.tif’ and convert it into a grayscale image, denoted with ‘img1’
Apply Fourier transform to img1 using fft (and fftshift) and display the amplitude and phase using abs and angle functions
Create a Gaussian lowpass filter and apply it to the Fourier coefficients of img1.
Perform inverse Fourier transform using ifft to recover the filtered image and display it to screen
Create a Gaussian highpass filter and apply it to the Fourier coefficients of img1. Using inverse Fourier transform to recover the filtered image and display it to screen
Explanation / Answer
Please refer below code
Here change the filename to Balloon.tif as I dont have the file with me
close all
clc
A = imread('corn.tif');
figure
image(A);
%%FFT of an image
FF = fft2(A);
%Magnitude part of FFT
abs(fftshift(FF));
%Phase part of FFT
angle(fftshift(FF));
%Applying gaussian lowpass filter on FFT image
h = fspecial('gaussian', [3, 3], 1)
J = imfilter(FF, h);
%Inverse FFT
IFF = ifft2(J);
%IFF = uint8(IFF);
figure
imshow(IFF,[])
[m n]=size(A);
f_shift=fftshift(FF);
p=m/2; q=n/2; d0=70;
%Gaussian High pass filter function
for i=1:m
for j=1:n
distance=sqrt((i-p)^2+(j-q)^2);
low_filter(i,j)=exp(-(distance)^2/(2*(d0^2)));
end
end
filter_apply=f_shift.*low_filter;
image_orignal=ifftshift(filter_apply);
image_filter_apply=abs(ifft2(image_orignal));
figure
imshow(image_filter_apply,[])
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.