2011-10-14 11 views
8

Quindi ho questa immagine 'I'. Prendo F = fft2 (I) per ottenere la trasformata di Fourier in 2D. Per ricostruirlo, potrei andare su ifft2 (F).Solo FFT inversa Matlab da fase/magnitudine

Il problema è che ho bisogno di ricostruire questa immagine solo dalla a) magnitudo eb) componenti di fase di F. Come posso separare questi due componenti della trasformata di Fourier e quindi ricostruire l'immagine da ciascuno di essi?

Ho provato le funzioni abs() e angle() per ottenere l'ampiezza e la fase, ma la fase uno non si ricostruirà correttamente.

Aiuto?

risposta

10

È necessaria una matrice con la stessa grandezza di F e 0 fasi, e un'altra con la stessa fase di F e di grandezza uniforme. Come hai notato, abs ti dà la magnitudine. Per ottenere la magnitudine uniforme della stessa matrice di fase, è necessario utilizzare angle per ottenere la fase e quindi separare la fase in parti reali e immaginarie.

> F_Mag = abs(F); %# has same magnitude as F, 0 phase 
> F_Phase = cos(angle(F)) + j*(sin(angle(F)); %# has magnitude 1, same phase as F 
> I_Mag = ifft2(F_Mag); 
> I_Phase = ifft2(F_Phase); 
+0

I don vedi questa funzione ffti() a cui fai riferimento, vuoi dire ifft2() forse? In caso contrario, hai un link alla documentazione per questo? Inoltre, non vedo questa funzione arg(). – Jordan

+0

Mi spiace, stavo usando la sintassi di Octave per 'arg' (equivalente a' angle' di Matlab) e sintassi inventata nella mia testa per 'ifft2'. – mtrw

+4

+1, 'F_Phase = exp (j * angle (F));' too! –

0

è troppo tardi per mettere un'altra risposta a questo post, ma ... comunque

@ zhilevan, è possibile utilizzare i codici che ho scritto usando la risposta di MTRW:

image = rgb2gray(imread('pillsetc.png')); 
subplot(131),imshow(image),title('original image'); 
set(gcf, 'Position', get(0, 'ScreenSize')); % maximize the figure window 
%::::::::::::::::::::: 
F = fft2(double(image)); 
F_Mag = abs(F); % has the same magnitude as image, 0 phase 
F_Phase = exp(1i*angle(F)); % has magnitude 1, same phase as image 
% OR: F_Phase = cos(angle(F)) + 1i*(sin(angle(F))); 
%::::::::::::::::::::: 
% reconstruction 
I_Mag = log(abs(ifft2(F_Mag*exp(i*0)))+1); 
I_Phase = ifft2(F_Phase); 
%::::::::::::::::::::: 
% Calculate limits for plotting 
% To display the images properly using imshow, the color range 
% of the plot must the minimum and maximum values in the data. 
I_Mag_min = min(min(abs(I_Mag))); 
I_Mag_max = max(max(abs(I_Mag))); 

I_Phase_min = min(min(abs(I_Phase))); 
I_Phase_max = max(max(abs(I_Phase))); 
%::::::::::::::::::::: 
% Display reconstructed images 
% because the magnitude and phase were switched, the image will be complex. 
% This means that the magnitude of the image must be taken in order to 
% produce a viewable 2-D image. 
subplot(132),imshow(abs(I_Mag),[I_Mag_min I_Mag_max]), colormap gray 
title('reconstructed image only by Magnitude'); 
subplot(133),imshow(abs(I_Phase),[I_Phase_min I_Phase_max]), colormap gray 
title('reconstructed image only by Phase');