## Friday, June 26, 2015

### 2D FFT: Binarization of 2D FFT of Wave Images: Part 01

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.

Wave Images of Different Frequencies

Figure 1 shows an wave image.

 Figure 1. 2D_wave_01.png
Our 2D FFT analysis of images, such as the one shown in Figure 1, is done with the following Matlab code.

figure;
imshow(wave_01);
title('Wave 01');

%% Do 2D FFT
wave_01_fft = fft2(double(wave_01)); %% convert image into double and apply 2D FFT to it
wave_01_fft = fftshift(wave_01_fft); %% shift the frequency spectrum's origin into the middle
wave_01_fft = abs(wave_01_fft); %% compute the magnitudes of the obtained transformed

wave_01_fft = log(wave_01_fft+1); %% transform the 2D FFT into the logspace
wave_01_fft = mat2gray(wave_01_fft); %% grayscale

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

%% Find the maximum value and its location in the spectrum
[value_max, location_max] = max(wave_01_fft(:));
[row_max, col_max] = ind2sub(size(wave_01_fft), location_max);
%% Find the maximum value and its location in the spectrum
[value_min, location_min] = min(wave_01_fft(:));
[row_min, col_min] = ind2sub(size(wave_01_fft), location_min);
%% Threshold and binarize
wave_01_fft_max = (wave_01_fft >= 0.90);
wave_01_fft_min = (wave_01_fft_max <= 0.1);
wave_01_fft(wave_01_fft_max) = 255;
wave_01_fft(wave_01_fft_min) = 0;
%% Shown in Figure 3 below.
figure;
imshow(wave_01_fft, []);
title('Wave 01 2D FFT Threshed');

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