user3497570
user3497570

Reputation: 25

How to specify and keep only a proportion of the Fourier Transforms of largest magnitude from an image

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?

Upvotes: 1

Views: 171

Answers (1)

Suever
Suever

Reputation: 65460

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

Upvotes: 3

Related Questions