%%%%%%To find the FFT and IFFT of a color Image
%%To read the file from host system
close all;
clear all;
clc;
I1=imread('Sunflower.bmp');
I2=rgb2gray(I1)
[m,n]=size(I2);
% To obtain the DFT of the image
Id=blkproc(I2,[8,8],'dft');
% plot(abs(dft,freq))
D=Id;
% % To filter zeros from matrix
pos=find(Id==0);
Id(Id==0)=[];
nbits=length(Id);
%To find the Compression Ratio based on no. of fft co-efficients
Cr=numel(I2)/numel(Id);
% To pad zeros to the fft signal
Mz=pad0(Id,pos,n);
% To convert vector to matrix
F=reshape(Mz,m,n);
% To obtain the Inverse DFT of the image
I3=blkproc(F,[8,8],'idft');
%# Create the gaussian filter with hsize = [5 5] and sigma = 2
G = fspecial('gaussian',[2 2],0.8);
%# Filter it
Ig = imfilter(I3,G,'same');
%# Display
imshow(Ig)
% To display the Reconstructed & the original image
I0=uint8(I2);figure(1),imshow(I1),title('Original image');
I4=uint8(Ig);
% I5=imadjust(I4,[0.3 1],[]);
figure(2),imshow(I4),title('Reconstructed image');
P=255;
MSE=mean((I1(:)-I4(:)).^2);
PSNR=10*log10(P^2/MSE);