Friday, June 26, 2015

2D FFT: Binarization of 2D FFT of Wave Images: Part 03



Problem
  
This post continues our series of posts on a programmatic investigation of the 2D FFT. In this post, we will address the question of computing 2D FFT of wave images and binarizing them to obtain the main pattern. The slide presentation for this post is available here.The previous post on the 2D FFT of wave images is here.

Wave Images of Different Frequencies



Figure 1 shows an wave image.

Figure 1. 2D_wave_03.png
Our 2D FFT analysis of images, such as the one shown in Figure 1, is done with the following Matlab code. 
 
wave_03 = imread('2D_wave_03', 'png');

figure;
imshow(wave_03);
title('Wave 03');

%% Do 2D FFT
wave_03_fft = fft2(double(wave_03)); %% convert image into double and apply 2D FFT to it
wave_03_fft = fftshift(wave_03_fft); %% shift the frequency spectrum's origin into the middle

wave_03_fft = abs(wave_03_fft); %% compute the magnitudes of the obtained transformed
wave_03_fft = log(wave_03_fft+1); %% transform the 2D FFT into the logspace
wave_03_fft = mat2gray(wave_03_fft); %% grayscale

figure;
imshow(wave_03_fft,[]); %% Display the result shown in Figure 2 below.
title('Wave 03 2D FFT Magn');

%% Find the maximum value and its location in the spectrum
[value_max, location_max] = max(wave_03_fft(:));
[row_max, col_max] = ind2sub(size(wave_03_fft), location_max);
%% Find the maximum value and its location in the spectrum
[value_min, location_min] = min(wave_03_fft(:));
[row_min, col_min] = ind2sub(size(wave_03_fft), location_min);
%% Threshold and binarize
wave_03_fft_max = (wave_03_fft >= 0.90);
wave_03_fft_min = (wave_03_fft_max <= 0.1);
wave_03_fft(wave_03_fft_max) = 255;

wave_03_fft(wave_03_fft_min) = 0; 
%% Shown in Figure 3 below.



imshow(wave_03_fft, []);




title('Wave 02 2D FFT Threshed'); 

Figure 2 displays the unthresholded result of the 2D FFT.

Figure 2. Unthresholded 2D FFT of image in Figure 1


Figure 3 below shows the thresholded and binarized version of the 2D FFT spectrum shown in Figure 2.  The center dot shows the complex 2D sinusoid with 0 frequencies along the x and y axes. The top left dot corresponds to a complex sinusoid whose magnitude corresponds to the frequency of the wave in Figure 1 moving north-west. The bottom right point corresponds to another
complex sinusoid whose magnitude corresponds to the frequency of the wave in Figure 1 moving
south-east. The magnitude of both vectors is greater than the magnitude of the two vectors in this post because the wave in Figure 1 has a larger frequency.

Figure 3. Thresholded and binarized 2D FFT of image in Figure 1