简体   繁体   中英

How to combine phase of one image with magnitude of another image in matlab and generate the inverse of the combined image

I have calculated fourier transform of two images ( img1 & img2 ) and displayed its phase and magnitude. I want to merge the phase of img1 and magnitude of img2 and generate a new image. How can I generate the combined image and also calculate its inverse. Below is my code:

imagesc(img1); 
img1 = fftshift(img1(:,:,2)); 
F = fft2(img1); 

figure;  
imagesc(log(abs(fftshift(F)))); colormap(gray); 
title('magnitude Spectrum'); 
set(gca,'position',[0 0 1 1],'units','normalized')  
figure; 

imagesc(angle(F)); colormap(gray); 
title('PhaseSpectrum'); 
set(gca,'position',[0 0 1 1],'units','normalized') 

figure;  
imagesc(img2); 
img2 = fftshift(img2(:,:,2)); 
F2 = fft2(img2); 

figure;  
imagesc(log(abs(fftshift(F2)))); colormap(gray); 
title('magnitude Spectrum'); 
set(gca,'position',[0 0 1 1],'units','normalized')  

figure; 
imagesc(angle(F2)); colormap(gray); 
title('PhaseSpectrum'); 
set(gca,'position',[0 0 1 1],'units','normalized')  

Assuming the two images are of the same size, you can combine the magnitude and phase by using the following formula:

combined = abs(F2) .* exp(i * angle(F));

Then obtaining the inverse is simply a matter of using ifft2 (perhaps followed by ifftshift depending on your application; I can't tell without more context whether you need to work with fftshift 'ed images or not):

combined_img = ifft2(combined);

If the images aren't the same size, you should first obtain frequency-domain representations of the same size with the following:

m = max(size(img1,1), size(img2,1));
n = max(size(img1,2), size(img2,2));
F = fft2(img1,m,n);
F2 = fft2(img2,m,n);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM