Unable to convert image back to time domain using IFFT!!

7 次查看(过去 30 天)
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 个评论
Matt J
Matt J 2022-9-22
编辑:Matt J 2022-9-22
It's not clear why you think the original image should be recoverable. In particular, when creating kspace, all phase information is discarded.
Rupika Raj
Rupika Raj 2022-9-22
编辑:Rupika Raj 2022-9-22
I want to know how the image gets affected if i shift some values of a line in kspace.

请先登录,再进行评论。

回答(1 个)

Alex Hanes
Alex Hanes 2022-10-25
The ifft() and ifftshift() function do not commute. Look at the series of steps you took (working outwards):
  1. Apply fft
  2. Apply fftshift
  3. Apply ifft
  4. 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);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by