Code take forever to run and output
Afficher commentaires plus anciens
HI, when i was running my code, only the first 2 figure shown up (Figure 1 and Figure 2), the others are not showing up. I run the code and leave it for more than an hour but only the first 2 figure shown up. The code run for more than an hour to run and it does not output the rest of the figures. May I know what are the problems?
codes:
clear all; close all; clc
%Read and display source image
imgA = imread('test1.jpg');
imgA = rgb2gray(imgA);
figure(1); imshow(imgA); title('Image from Source');
%Convert source image to Grayscale
imgB = imread('test2.jpg');
imgB = rgb2gray(imgB);
figure(2); imshow(imgB); title('Image from Intensity');
%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 = 468;
iteration = 1100;
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
if error>464
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);
%RMSE Error
error = [error; (1/sqrt(rowsimgA*colsimgA)*sqrt(sum(sum(abs(image_recon)-abs(imgB)).^2)))];
else
g=1;
break;
end
end
fprintf('No. of iterations required to meet the error threshold is %i\n',i)
figure (5)
i = 1:1:length(error);
plot(i,(error'));
title('Error');
grid on
% Verification of amplitude and phase values
C1=abs(image_fft_recon./image_fft_recon);
C2=imgA./imgA;
if 'C1=C2'
disp ('Pixel Locations where the amplitude is non-zero the phase has a value')
else
disp('answers not verified')
end
figure(3);
imagesc(abs(image_void)),colorbar;
title('exponential img');
figure(4);
imagesc(abs(image_fft_recon)), colorbar;
title('constructed img');
phase_image=(abs(image_fft_recon));
figure(6),plot(phase_image), title('Phase diagram');
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
