I'm stuck in a loop when trying to do image processing.

1 vue (au cours des 30 derniers jours)
Westin Messer
Westin Messer le 28 Fév 2018
Commenté : Rik le 2 Mar 2018
Hello, I have written this code to filter an image however the outputted image never appears, does anyone know what I am doing wrong?
clc;
clear all;
close all;
im1=imread('peppers.png');
im3=im2double(im1);
[n,m]=size(im3);
c1=0;
h = waitbar(0,'Calculating XXX please wait......');
k=1;l=1;
for l=0:1:m-1
for k=0:1:n-1
for x=0:1:n-1
for y=0:1:m-1
a=x+1;b=y+1;
c= im3(a,b) * exp(-1i*2*pi*(k*x/n + l*y/m));
c1=c1+c;
end
end
aa=l+1;bb=k+1;
im(bb,aa)=c1;
c1=0;
end
waitbar(l / m);
end
ims = im*255;
close(h)
imshow(ims);title('XXX plot');
figure
imshow(log(abs(ims)),[-1 5]); colormap(jet); colorbar;title('absolute value of XXX plot');
  2 commentaires
Rik
Rik le 28 Fév 2018
I think your loop was still working. You should really start with a small example when you have nested loops. I replaced the inner two loops with vectorized code and still it took 20 seconds to get the outermost loop to 5. See my edit and comments below.
You should re-think what you want to calculate and how you want to do it.
clc;
clear variables;%don't use clear all, there is no reason to
close all;
im1=imread('peppers.png');
im3=im2double(im1);
im3=mean(im3,3);%convert RGB to grayscale
[n,m]=size(im3);
c1=0;
h = waitbar(0,'Calculating XXX please wait......');
k=1;l=1;tic
for l=0:1:m-1
for k=0:1:n-1
if toc>20,break,end%if it takes too much time, exit the loop
[y,x]=meshgrid(0:1:m-1,0:1:n-1);
a=x+1;b=y+1;
aaa=exp(-1i*2*pi*(k*x/n + l*y/m));
c= im3.* exp(-1i*2*pi*(k*x/n + l*y/m));
c1=c1+sum(c(:));
aa=l+1;bb=k+1;
im(bb,aa)=c1;
c1=0;
end
waitbar(l / m);
end
ims = im*255;
close(h)
Rik
Rik le 2 Mar 2018
For future people stumbling onto this post, a continued discussion and a working solution are posted here.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by