Tuesday, April 21, 2015

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

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 continue our investigation of horizontal lines by modifying their thickness. The previous post is here.

Centrally Positioned Horizontal Line Thickened

Figure 1 shows a horizontal line centrally positioned in the image and thickened.

Figure 1. Centrally positioned horizontal line thickened (hor_line_01d.jpg)

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

title('HOR LINE 01d');

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
fftHorLine01d = fft2(double(img_hor_line_01d));
fftHorLine01d = fftshift(fftHorLine01d);
fftHorLine01d = abs(fftHorLine01d);
fftHorLine01d = log(fftHorLine01d+1);
fftHorLine01d = mat2gray(fftHorLine01d);

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.

imshow(fftHorLine01d), colormap(gray);
title('HOR LINE 01d 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
fftHorLine01d_PHASE = fft2(double(img_hor_line_01d));
fftHorLine01d_PHASE = fftshift(fftHorLine01d_PHASE);
fftHorLine01d_PHASE = angle(fftHorLine01d_PHASE);

imshow(fftHorLine01d_PHASE, [-pi, pi]), colormap(gray);
title('HOR LINE 01d FFT2 Phase');

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