Random phase generator inside a iteration loop

1 visualización (últimos 30 días)
Soong Wei Kang
Soong Wei Kang el 7 de Jul. de 2020
Editada: Soong Wei Kang el 9 de Jul. de 2020
I am writing a phase retrieval codes, I need a random phase generator inside an iteration loop, but i don't really know how to code it inside my codes. The criteria to exit the loop is that the retrieved phase from source image is equal to the phase of the target image. May I get some help on this? Thank you.
These are my codes:
clear all; close all; clc; workspace;
%Read and import images
imgA = imread('image1.jpg');
imgB = imread('image2.jpg');
%-------------------Make both images the same size-----------------------%
%Get the size of image A
[rowsimgA colsimgA numberOfColorChannelsimgA] = size(imgA);
%Get the size of image B
[rowsimgB colsimgB numberOfColorChannelsimgB] = size(imgB);
%Check if lateral sizes match
if rowsimgB ~= rowsimgA || colsimgA ~= colsimgB
imgB = imresize(imgB, [rowsimgA colsimgA]);
end
%Display images
figure, imshow(imgA)
title('First Image')
figure, imshow(imgB)
title('Second Image')
%Convert images to double
imgA = im2double(imgA);
imgB = im2double(imgB);
%2D FFT
fftA = fft2(imgA);
fftB = fft2(imgB);
%Decompose images into amplitude only
imgA_amp = abs(fftA);
imgB_amp = abs(fftB);
%Decompose images into phase only
imgA_phase = angle(fftA);
imgB_phase = angle(fftB);
%Display images with amplitude only
figure, imshow(abs(fftA));
title('Amplitude of first image')
figure, imshow(abs(fftB));
title('Amplitude of second image')
%Display images with phase only
figure, imshow(angle(fftA));
title('Phase of first image')
figure, imshow(angle(fftB));
title('Phase of second image')
%Switch the amplitude and phase of both images
out1 = imgA_amp .* exp(imgB_phase);
out2 = imgB_amp .* exp(imgA_phase);
%Inverse FFT
out1 = real(ifft2(out1));
out2 = real(ifft2(out2));
%Display the images
figure;
imshow(out1, []);
figure;
imshow(out2, []);

Respuestas (0)

Categorías

Más información sobre Geometric Transformation and Image Registration en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by