Unable to convert image back to time domain using IFFT!!
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I've been using MATLAB to analyse the properties of image in frequency domain. For this i used the cameraman.jpg image. i was able to find its FFT but unfortunately i am unable to convert the image back to original. can anyone please help!?
I have added the code and images below.
Thanks in advance!


img = imread('cameraman.tif');
figure;
imshow(img, []);
title('Input Image');
imRef = fftshift(fft((img),[],1),1);
imRef = fftshift(fft(imRef,[],2),2);
kspace = squeeze(sqrt(sum(abs(imRef).^2, 4)));
figure;
imshow(log(kspace), []);
title('Input kspace');
shifted_127(127,:) = circshift(kspace(127,:),5); % shifted 5+1 places
shifted = kspace ;
shifted(127,:) = shifted_127(127,:);
figure;
imshow(log(shifted), []);
title('Shifted kspace');
imRef1 = ifftshift(ifft(shifted,[],1),1);
imRef1 = ifftshift(ifft(imRef1,[],2),2);
kspace1 = squeeze(sqrt(sum(abs(imRef1).^2, 4)));
figure;
imshow(kspace1,[]);
title('Out image');
2 Kommentare
Antworten (1)
Alex Hanes
am 25 Okt. 2022
The ifft() and ifftshift() function do not commute. Look at the series of steps you took (working outwards):
- Apply fft
- Apply fftshift
- Apply ifft
- Apply ifftshift
Instead, you need to swap the order of steps 3 and 4 since the order of function operations matters. You can convince yourself of this using a simple sine function:
% Create a sine function:
t = (0:0.01:25)';
y1 = sin(t);
yFFT = fftshift(fft(y1)); % Calculate DFT, then fftshift
y2 = real(ifftshift(ifft(yFFT))); % Apply ifft, then ifftshift
y3 = real(ifft(ifftshift(yFFT))); % Apply ifftshift, then ifft
% See if y1 matches y2, y3:
diff1 = y1 - y2; % Calculate Difference
diff2 = y1 - y3; % Calculate Difference
% Set Values = 0 if < eps:
diff1(abs(diff1) <= 10.*eps) = 0;
diff2(abs(diff2) <= 10.*eps) = 0;
% Get Number of Non-zero Differences:
N1 = nnz(diff1);
N2 = nnz(diff2);
figure(1); clf; zoom on; hold on;
plot(t,y1,'k-','LineWidth',2);
plot(t,y2,'b-','LineWidth',2);
plot(t,y3,'r--','LineWidth',2);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matched Filter and Ambiguity Function finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!