1

I want to write a short MATLAB program that enables me to specify and keep only a proportion of the Fourier Transforms of largest magnitude from an image representation.

Here is my code so far, where 'image123' is a 256x256 uint8:

I= image123;
F = fft2(I); 
F = fftshift(F); 
F = abs(F); % Get the magnitude
F = log(F + 1); 
F = mat2gray(F); 
figure, imshow(F,[]) 

If I increase my value of 1 in 'F = log(F + 1)' will this increase the magnitude of the Fourier transform?

Suever
  • 64,497
  • 14
  • 82
  • 101
user3497570
  • 25
  • 1
  • 8
  • Your title doesn't match up with your code at all. Are you just trying to visualize the FFT or are you actually trying to set all values of the FFT that are less than a particular value to zero and then reconstruct the image from that? – Suever Mar 29 '17 at 14:20
  • @Suever yes I want to to set all values of the FFT that are less than a value to zero and then reconstruct the image – user3497570 Mar 29 '17 at 14:23

1 Answers1

3

You'll want to use a binary mask to set all values below a given threshold to zero and then use ifft2 to create an image from this modified Fourier data

% Load in some sample data
tmp = load('mri');
I = tmp.D(:,:,12);

% Take the 2D Fourier Transform
F = fft2(I);

% Set this to whatever you want
threshold = 2000;

% Force all values less than this cutoff to be zero
F(abs(F) < threshold) = 0;

% Take the inverse Fourier transform to get your image back
I2 = ifft2(F);

% Plot them
figure;
subplot(1,2,1);    
imshow(I, []);
title('Original')

subplot(1,2,2);
imshow(I2, []);
title('Filtered')

enter image description here

Suever
  • 64,497
  • 14
  • 82
  • 101
  • what should I be setting up my 'D' as? @Suever – user3497570 Mar 30 '17 at 10:04
  • @user3497570 you don't have a D. You already have I (your image) – Suever Mar 30 '17 at 11:26
  • I don't understand the line: I = tmp.D(:,:,12); What does the D(:,:,12) mean? – user3497570 Mar 30 '17 at 12:04
  • @user3497570 As I said, you don't need to worry about it because `mri` is a built-in dataset that I'm using as an example. `tmp.D` is a 3D volume and I'm pulling out the 12th slice of the data. In your case, you just replace that entire line with `I = image123` like you have in your original post. – Suever Mar 30 '17 at 14:10
  • thank you. Why are my values for F coming out as complex values? – user3497570 Mar 30 '17 at 15:07