Monday, April 27, 2015

2D FFT: Effects of Location & Thickness of Diagonal Lines on 2D Magnitude & Phase: Part 01


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 switch to diagonal lines. We will modify their location by modifying in the image without modifying their thickness. The MATLAB source of our programmatic investigation is in the last section of this post. The previous post on vertical lines is here.

Diagonal Line from Top Left to Bottom Right



Figure 1 shows a diagonal line going from top left to bottom right.

Figure 1. Diagonal line from top left to bottom right (dig_tl_br_line_01a.jpg)
We add the path, read the image, and display it. 
 
addpath C:\Users\Vladimir\research\images\
ImgDigTlBrLine_01a = imread('dig_tl_br_line_01a', 'jpg');

figure;
imshow(ImgDigTlBrLine_01a);
title('Dig TL-BR LINE 01a');
  

Now we compute the 2D FFT of the image in Figure 1. 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
fftDigTlBrLine01a = fft2(double(ImgDigTlBrLine_01a));
fftDigTlBrLine01a = fftshift(fftDigTlBrLine01a);
fftDigTlBrLine01a = abs(fftDigTlBrLine01a);
fftDigTlBrLine01a = log(fftDigTlBrLine01a+1);
fftDigTlBrLine01a = mat2gray(fftDigTlBrLine01a);


The magnitude image is shown in Figure 2. As can be seen in Figure 2, the FFT magnitude shows a diagonal line in the center orthogonal to the diagonal line in Figure 1. Note that there are other lines orthogonal to the diagonal line in Figure 1 but less pronounced than the other lines. This indicates that there are other frequencies detected in the image.

figure;
imshow(fftDigTlBrLine01a);
colormap(gray);
title('Dig TL-BR LINE 01a FFT2 Magnitude');

Figure 2. 2D FFT Magnitude of Figure 1
The phase component can be computed and displayed by the following MATLAB code.



%%% fft2 phase
fftDigTlBrLine01a_PHASE = fft2(double(ImgDigTlBrLine_01a));
fftDigTlBrLine01a_PHASE = fftshift(fftDigTlBrLine01a_PHASE);
fftDigTlBrLine01a_PHASE = angle(fftDigTlBrLine01a_PHASE);

figure;
imshow(fftDigTlBrLine01a_PHASE, [-pi, pi]);
colormap(gray);

title('Dig TL-BR LINE 01a FFT2 Phase');


The MATLAB source is below.


MATLAB Source for 2D FFT Investigation of Diagonal Lines



%%% ======================================================================
%%% Programmatic Investigation of the Effects of Location and Thickness
%%% of top-left-bottom-right diagonal lines on the magnitude and phase
%%% components of 2D FFT.
%%%
%%% Author: Vladimir Kulyukin
%%% ======================================================================


addpath C:\Users\Vladimir\research\images\

%%% ================== 2D FFT of DIG TL-BR LINE 01a ======================
ImgDigTlBrLine_01a = imread('dig_tl_br_line_01a', 'jpg');

figure;
imshow(ImgDigTlBrLine_01a);
title('Dig TL-BR LINE 01a');

%% ff2 magnitude
fftDigTlBrLine01a = fft2(double(ImgDigTlBrLine_01a));
fftDigTlBrLine01a = fftshift(fftDigTlBrLine01a);
fftDigTlBrLine01a = abs(fftDigTlBrLine01a);
fftDigTlBrLine01a = log(fftDigTlBrLine01a+1);
fftDigTlBrLine01a = mat2gray(fftDigTlBrLine01a);

figure;
imshow(fftDigTlBrLine01a);
colormap(gray);
title('Dig TL-BR LINE 01a FFT2 Magnitude');

%%% fft2 phase
fftDigTlBrLine01a_PHASE = fft2(double(ImgDigTlBrLine_01a));
fftDigTlBrLine01a_PHASE = fftshift(fftDigTlBrLine01a_PHASE);
fftDigTlBrLine01a_PHASE = angle(fftDigTlBrLine01a_PHASE);

figure;
imshow(fftDigTlBrLine01a_PHASE, [-pi, pi]);
colormap(gray);
title('Dig TL-BR LINE 01a FFT2 Phase');

%%% ================== 2D FFT of DIG TL-BR LINE 01b ======================
ImgDigTlBrLine_01b = imread('dig_tl_br_line_01b', 'jpg');

figure;
imshow(ImgDigTlBrLine_01b);
title('Dig TL-BR LINE 01b');

%%% ff2 magnitude
fftDigTlBrLine01b = fft2(double(ImgDigTlBrLine_01b));
fftDigTlBrLine01b = fftshift(fftDigTlBrLine01b);
fftDigTlBrLine01b = abs(fftDigTlBrLine01b);
fftDigTlBrLine01b = log(fftDigTlBrLine01b+1);
fftDigTlBrLine01b = mat2gray(fftDigTlBrLine01b);

figure;
imshow(fftDigTlBrLine01b);
colormap(gray);
title('Dig TL-BR LINE 01b FFT2 Magnitude');

%%% fft2 phase
fftDigTlBrLine01b_PHASE = fft2(double(ImgDigTlBrLine_01b));
fftDigTlBrLine01b_PHASE = fftshift(fftDigTlBrLine01b_PHASE);
fftDigTlBrLine01b_PHASE = angle(fftDigTlBrLine01b_PHASE);

figure;
imshow(fftDigTlBrLine01b_PHASE, [-pi, pi]);
colormap(gray);
title('Dig TL-BR LINE 01b FFT2 Phase');

%%% ================== 2D FFT of DIG TL-BR LINE 01c ======================

ImgDigTlBrLine_01c = imread('dig_tl_br_line_01c', 'jpg');

figure;
imshow(ImgDigTlBrLine_01c);
title('Dig TL-BR LINE 01c');

%%% ff2 magnitude
fftDigTlBrLine01c = fft2(double(ImgDigTlBrLine_01c));
fftDigTlBrLine01c = fftshift(fftDigTlBrLine01c);
fftDigTlBrLine01c = abs(fftDigTlBrLine01c);
fftDigTlBrLine01c = log(fftDigTlBrLine01c+1);
fftDigTlBrLine01c = mat2gray(fftDigTlBrLine01c);

figure;
imshow(fftDigTlBrLine01c);
colormap(gray);
title('Dig TL-BR LINE 01c FFT2 Magnitude');

%%% fft2 phase
fftDigTlBrLine01c_PHASE = fft2(double(ImgDigTlBrLine_01c));
fftDigTlBrLine01c_PHASE = fftshift(fftDigTlBrLine01c_PHASE);
fftDigTlBrLine01c_PHASE = angle(fftDigTlBrLine01c_PHASE);

figure;
imshow(fftDigTlBrLine01c_PHASE, [-pi, pi]);
colormap(gray);
title('Dig TL-BR LINE 01c FFT2 Phase');

%%% ================== 2D FFT of DIG TL-BR LINE 01d ======================
ImgDigTlBrLine_01d = imread('dig_tl_br_line_01d', 'jpg');

figure;
imshow(ImgDigTlBrLine_01d);
title('Dig TL-BR LINE 01d');

%%% ff2 magnitude
fftDigTlBrLine01d = fft2(double(ImgDigTlBrLine_01d));
fftDigTlBrLine01d = fftshift(fftDigTlBrLine01d);
fftDigTlBrLine01d = abs(fftDigTlBrLine01d);
fftDigTlBrLine01d = log(fftDigTlBrLine01d+1);
fftDigTlBrLine01d = mat2gray(fftDigTlBrLine01d);

figure;
imshow(fftDigTlBrLine01d);
colormap(gray);
title('Dig TL-BR LINE 01d FFT2 Magnitude');

%%% fft2 phase
fftDigTlBrLine01d_PHASE = fft2(double(ImgDigTlBrLine_01d));
fftDigTlBrLine01d_PHASE = fftshift(fftDigTlBrLine01d_PHASE);
fftDigTlBrLine01d_PHASE = angle(fftDigTlBrLine01d_PHASE);

figure;
imshow(fftDigTlBrLine01d_PHASE, [-pi, pi]);
colormap(gray);
title('Dig TL-BR LINE 01d FFT2 Phase');

%%% ================== 2D FFT of DIG TL-BR LINE 01e ======================
ImgDigTlBrLine_01e = imread('dig_tl_br_line_01e', 'jpg');

figure;
imshow(ImgDigTlBrLine_01e);
title('Dig TL-BR LINE 01e');

%%% ff2 magnitude
fftDigTlBrLine01e = fft2(double(ImgDigTlBrLine_01e));
fftDigTlBrLine01e = fftshift(fftDigTlBrLine01e);
fftDigTlBrLine01e = abs(fftDigTlBrLine01e);
fftDigTlBrLine01e = log(fftDigTlBrLine01e+1);
fftDigTlBrLine01e = mat2gray(fftDigTlBrLine01e);

figure;
imshow(fftDigTlBrLine01e);
colormap(gray);
title('Dig TL-BR LINE 01e FFT2 Magnitude');

%%% fft2 phase
fftDigTlBrLine01e_PHASE = fft2(double(ImgDigTlBrLine_01e));
fftDigTlBrLine01e_PHASE = fftshift(fftDigTlBrLine01e_PHASE);
fftDigTlBrLine01e_PHASE = angle(fftDigTlBrLine01e_PHASE);

figure;
imshow(fftDigTlBrLine01e_PHASE, [-pi, pi]);
colormap(gray);
title('Dig TL-BR LINE 01e FFT2 Phase');

%%% ================== 2D FFT of DIG TL-BR LINE 01f ======================

ImgDigTlBrLine_01f = imread('dig_tl_br_line_01f', 'jpg');

figure;
imshow(ImgDigTlBrLine_01f);
title('Dig TL-BR LINE 01f');

%%% ff2 magnitude
fftDigTlBrLine01f = fft2(double(ImgDigTlBrLine_01f));
fftDigTlBrLine01f = fftshift(fftDigTlBrLine01f);
fftDigTlBrLine01f = abs(fftDigTlBrLine01f);
fftDigTlBrLine01f = log(fftDigTlBrLine01f+1);
fftDigTlBrLine01f = mat2gray(fftDigTlBrLine01f);

figure;
imshow(fftDigTlBrLine01f);
colormap(gray);
title('Dig TL-BR LINE 01f FFT2 Magnitude');

%%% fft2 phase
fftDigTlBrLine01f_PHASE = fft2(double(ImgDigTlBrLine_01f));
fftDigTlBrLine01f_PHASE = fftshift(fftDigTlBrLine01f_PHASE);
fftDigTlBrLine01f_PHASE = angle(fftDigTlBrLine01f_PHASE);

figure;
imshow(fftDigTlBrLine01f_PHASE, [-pi, pi]);
colormap(gray);
title('Dig TL-BR LINE 01f FFT2 Phase');

%%% ======================================================================