Tuesday, April 21, 2015

2D FFT: Effects of Location & Thickness of Horizontal Lines on 2D FFT Magnitude & Phase: Part 02


Problem
  
This post continues our series of posts on a programmatic investigation of the effects of the location and thickness of horizontal, vertical, and diagonal lines on the magnitude and phase components of 2D FFT. In this post, we will keep studying horizontal lines. The previous post is here.

Horizontal Line Shifted Downward



We will start our investigation with the image in Figure 1 that shows a horizontal line shifted downward.

Figure 1. Horizontal line shifted downward (hor_line_01c.jpg)


We add the path, read the image, and display it. 
 
img_hor_line_01c = imread('hor_line_01c', 'jpg');

figure;
imshow(img_hor_line_01c);
title('HOR LINE 01c');


Here is how we compute the 2D FFT of the image. The image is converted into a 2D double matrix. The fftshift command positions the 0,0 origin to the center of the image. We compute the absolute magnitude of each value in the 2D matrix and take the log of each value. 1 is added to each value before taking the log, because log(0) is not defined.
 
%% ff2 magnitude
fftHorLine01c = fft2(double(img_hor_line_01c));
fftHorLine01c = fftshift(fftHorLine01c);
fftHorLine01c = abs(fftHorLine01c);
fftHorLine01c = log(fftHorLine01c+1);
fftHorLine01c = mat2gray(fftHorLine01c);


The magnitude image is shown in Figure 2. As can be seen in Figure 2, the FFT magnitude shows a line orthogonal to the line in Figure 1.


figure, imshow(fftHorLine01c), colormap(gray);
title('HOR LINE 01c FFT2 Magnitude');


Figure 2. 2D FFT magnitude of Figure 1
We compute the phase component and display it. The image is shown in Figure 3.

 %% fft2 phase
fftHorLine01c_PHASE = fft2(double(img_hor_line_01c));
fftHorLine01c_PHASE = fftshift(fftHorLine01c_PHASE);
fftHorLine01c_PHASE = angle(fftHorLine01c_PHASE);

  
figure;
imshow(fftHorLine01c_PHASE, [-pi, pi]), colormap(gray);
title('HOR LINE 01c FFT2 Phase');


Figure 3. 2D FFT phase of Figure 1
The complete  MATLAB source code is in this post. The next post is here.