Complex output after applying inverse fourier transform
Show older comments
I'm working on an image reconstruction project by using the method of Fast Fourier Transform (FFT). The code works well and output real matrix when all the pixels in the image are taken into account. However, after I extract the data by truncating the matrix of "Centered Fast Fourier Transform", the reconstructed image becomes a complex uint8 matrix and the following warning are displayed:
"Warning: Displaying real part of complex input.
> In images.internal.imageDisplayValidateParams>validateCData (line 146)
In images.internal.imageDisplayValidateParams (line 30)
In images.internal.imageDisplayParseInputs (line 79)
In imshow (line 253)
In Task2_Cross (line 38) "
clear all; close all; clc
Original_image = imread('Original Image');
figure(1);imshow(Original_image); title('Original Image');
% Convert the original RGB image to a grayscale image, if needed
Original_image = rgb2gray(Original_image);
figure(2); imshow(Original_image); title('Gray Image');
% Get the 2D Fast Fourier Transform (FFT) of an image
Fast_Fourier_Transform = fft2(Original_image);
% Fourier transform of an image
% Convert from complex double to double
Absolute = abs(Fast_Fourier_Transform);
figure(3);imshow(Absolute,[]);title('Fourier transform of an image');
% Get the centered spectrum
Centered_Fast_Fourier_Transform = fftshift(Fast_Fourier_Transform);
figure(4);imshow(abs(Centered_Fast_Fourier_Transform),[]);title('Centered fourier transform of Image')
% Apply log transform
Log_Transform = log(1+abs(Centered_Fast_Fourier_Transform));
figure(5);imshow(Log_Transform,[]);title('log transformed Image')
% Reconstruct the Image
% Uncomment the following lines for data extraction
Centered_Fast_Fourier_Transform = Centered_Fast_Fourier_Transform(6:251,:)
Centered_Fast_Fourier_Transform = Centered_Fast_Fourier_Transform(:,6:251)
Inverse_Centered_Fast_Fourier_Transform = ifftshift(Centered_Fast_Fourier_Transform);
Recontructed_image = ifft2(Inverse_Centered_Fast_Fourier_Transform);
% Convert to unit8
Recontructed_image = uint8(Recontructed_image)
figure(6);imshow(Recontructed_image,[]),title('reconstructed Image (FFT)')
As I know, when I apply FFT on real image A, I will get a complex matrix B. If I apply the inverse Fast Fourier Transform on this complex matrix, I should get a real reconstructed image C. May I know why the code doesn't work after I truncate the matrix? And how to fix it? Thank you.
Accepted Answer
More Answers (0)
Categories
Find more on Read, Write, and Modify Image in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!