Gerchberg–Saxton algorithm/ Fast Fourier transform/ Phase Retreiveal algorithm
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, this is my Gerchberg–Saxton algorithm codes that perform fft and ifft with the purpose of retrieve the phase of the images. I need an error function in my codes to exit the for loop but I am not sure how to do it. Can anyone help me on this? I really appreciate your help, thank you.
These are the codes:
clear all; close all; clc
%Read and display source image
imgA = imread('void.jpg');
imgA = rgb2gray(imgA);
figure(1); imshow(imgA); title('Image from Source');
%Convert source image to Grayscale
imgB = imread('void2.jpg');
imgB = rgb2gray(imgB);
figure(2); imshow(imgB); title('Grayscale Image');
%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
imgA = im2double(imgA);
imgB = im2double(imgB);
error = [];
iteration = 200;
image_void = fftshift(imgB);
image_void = ifft2(image_void);
image_void = fftshift(image_void);
%Decompose into amplitude and phase (image is converted into double)
for i=1:iteration
image_fft_recon = abs(imgA) .* exp(1i*angle(image_void));
image_recon = fftshift(image_fft_recon);
image_recon = fft2(image_recon);
image_recon = fftshift(image_recon);
image_fft_recon2 = abs(imgB) .* exp(1i*angle(image_recon));
image_void = fftshift(image_fft_recon2);
image_void = ifft2(image_void);
image_void = fftshift(image_void);
end
figure(3);
imagesc(abs(image_void)),colorbar;
title('exponential img');
figure(4);
imagesc(abs(image_fft_recon)), colorbar;
title('constructed img');
0 Kommentare
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!