Image Analysis Ass1

advertisement
Image Analysis
Mandatory assignment 1
Henrik Skovsgaard & Usman Shabbir
Fourier transform is an important tool in signal processing and could also be employed in the field of
image analysis. An image can be translated from spatial domain to frequency domain, processed and
than translated back into spatial domain using various techniques such as Fourier Transform or
Convolution.
The Fourier transform of a continuous function f(x), where x is a real variable can be written as:

F (u ) 
 f ( x) exp  juxdx

Where j =
1
By using the inverse fourier transform we can go from fourier sapce to spatial domain

f ( x) 
 F (u ) exp  j 2uxdu

The Fourier transform of a real function is generally complex, which means:
F(u) = R(u) + jI(u)
Where R(u) and I(u) are the real and imaginary components of F(u) respectively. In the exponential
form it is given as
F (u)  F (u) e j (u )
Where the magnitude of F(u) is calculated using

F (u)  R 2 (u)  I 2 (u)1 / 2

and the phase can be calculated as
 I (u ) 

 R(u ) 
In the Matlab we took two images ‘mcatdog.jpg’ and ‘cameraman.tif’. We first converted the two
images to 256X256 grayscale and than converted the images from spatial domain to frequency domain
 (u )  tan 1 
using the Matlab function fft2. The real part of frequency domain images were plotted and can be seen
in the plots labeled ‘Fourier (real part): mcatdog.jpg' and 'Fourier (real part): cameraman.tif' given
below.
Original Images in spatial domain
Real pars of ‘mcatdog.jpg’ and ‘cameraman.tif' in frequency domain
After the inverse Fourier transformation the images were plotted in spatial domain without any other
alternation. The results can been seen from the images below
Reconstructed images after the inverse transformation
Then we calculated the magnitude and phase of the images by using the abs and angle functions
respectively. We than carried out an inverse Fourier transformation using the Matlab functions ifft2.
And before displaying the images in spatial domain we swapped the phases of the two images. The
result of which can be seen in the images given below.
Images after the phase has been swapped
Conclusion
From the assignment one can conclude that Fourier transform is an important tool in image analysis
and in frequency domain the phase part of an image as compared to the magnitude part is somewhat
more important as this has been illustrated from the swapped images shown.
Furthermore we can conclude by looking at the swapped images, that most of the information is saved
in the phase. The magnitudes are just “spread” over the images and will appear as blurred.
Code documentation can be found at:
http://www.itu.dk/people/usmandk/3rd%20Semester/Image%20Analysis/as1/
The Matlab code
%read first image
RGB = imread('mcatdog.jpg');
%convert image to greysale
I = rgb2gray(RGB);
%scale image to 256x256
I1 = I([110:365],[195:450]);
%read second image
I2=imread('cameraman.tif');
%draw image
figure(1);imshow(I1);title('Greyscale image: mcatdog.jpg','FontSize',10);
figure(2);imshow(I2);title('Greyscale image: cameraman.tif','FontSize',10);
%Convert images fourier space
I1fourier=fft2(double(I1));
I2fourier=fft2(double(I2));
%draw image
figure(3);imshow(real(I1fourier));title('Fourier (real part): mcatdog.jpg','FontSize',10);
figure(4);imshow(real(I2fourier));title('Fourier (real part): cameraman.tif','FontSize',10);
%calculate the magnitude
Mag1=abs(I1fourier);
Mag2=abs(I2fourier);
%get the phase
phase1=angle(I1fourier);
phase2=angle(I2fourier);
%Reconstruct the image
Irecon1fourier=Mag1.*exp(i*phase1);
Irecon2fourier=Mag2.*exp(i*phase2);
%Move from fourier to spatial
Irecon1inverse=real(ifft2(Irecon1fourier));
Irecon2inverse=real(ifft2(Irecon2fourier));
figure(5);imshow(Irecon1inverse,[]);title('Spatial reconstruction: mcatdog.jpg','FontSize',10);
figure(6);imshow(Irecon2inverse,[]);title('Spatial reconstruction: cameraman.tif','FontSize',10);
%Swap phases
Swap1=Mag1.*exp(i*phase2);
Swap2=Mag2.*exp(i*phase1);
%Move from fourier to spatial
Swap1spatial=real(ifft2(Swap1));
Swap2spatial=real(ifft2(Swap2));
figure(7);imshow(Swap1spatial,[]);title('Swap1: mcatdog.jpg','FontSize',10);
figure(8);imshow(Swap2spatial,[]);title('Swap2: cameraman.tif','FontSize',10);
Download