what is wrong here? ??? Error using ==> times Matrix dimensions must agree.

i = imread('peppers.png');
red = i(:,:,1);
green = i(:,:,2);
blue = i(:,:,3);
subplot(4,2,1);imshow(i);title('original image');
subplot(4,2,2);imshow(red);title('red');
subplot(4,2,3);imshow(green);title('green');
subplot(4,2,4);imshow(blue);title('blue');
A = cat(3,red,green,blue);
subplot(4,2,5);imshow(A);title('Combined again');
Fi=fftshift(double(A));
[m,n]=size(A);
[x,y]=meshgrid(1:n,1:m);
x=x-(n+1)/2;
y=y-(m+1)/2;
d=sqrt(x.^2+y.^2);
d0=30;
ghpf=1-exp(-d.^2/(2*d0.^2));
j=ifft2(fftshift(Fi.*ghpf));
subplot(4,2,6);imshow(j);title('new');
the output here is :
??? Matrix dimensions must agree.
Error in ==> testRgb at 27
j=ifft2(fftshift(Fi.*ghpf));

2 commentaires

You define a Fi and you use fi in that line
i just noted that, and edited it but still the same error.
thank you

Connectez-vous pour commenter.

 Réponse acceptée

Never do this with an image:
[m,n]=size(A);
Why not? Because if A is RGB, which yours is, then your n is the number of columns times the number of color channels. So it's basically 3 times the number of columns, not the number of columns like you thought.
Do this instead:
[rows, columns, numberOfColorChannels] = size(A);
I'm also begging you to not have your code look like an alphabet soup mess of a program. Use descriptive variable names (not single letters), and add lots of comments. I would not hire a person who wrote code that doesn't follow those two requirements of good programming.

Plus de réponses (1)

Hi,
There is two small but crucial errs - see the command below:
%...
Fi=fftshift(double(A)); % NOTE your assigned variable name
[m, n, ooo]=size(A); % 1st ERR => NB: size of A is 225-by-225-by-3. Thus, you'd need the 3rd output as well
[x,y]=meshgrid(1:m,1:n);
x=x-(n+1)/2;
y=y-(m+1)/2;
d=sqrt(x.^2+y.^2);
d0=30;
ghpf=1-exp(-d.^2/(2*d0.^2));
% j=ifft2(fftshift(fi.*ghpf)); % 2nd ERR: Need to be Fi instead of fi
j=ifft2(fftshift(Fi.*ghpf));
subplot(4,2,6);imshow(j);title('new');
Good luck

3 commentaires

Thank you sulaymon ,
i did what you told me and i still have the exact same Err.
i = imread('peppers.png');
red = i(:,:,1);
green = i(:,:,2);
blue = i(:,:,3);
subplot(4,2,1);imshow(i);title('original image');
subplot(4,2,2);imshow(red);title('red');
subplot(4,2,3);imshow(green);title('green');
subplot(4,2,4);imshow(blue);title('blue');
A = cat(3,red,green,blue);
subplot(4,2,5);imshow(A);title('Combined again');
Fi=fftshift(double(A));
[m,n, ooo]=size(A);
[x,y,]=meshgrid(1:n,1:m);
x=x-(n+1)/2;
y=y-(m+1)/2;
d=sqrt(x.^2+y.^2);
d0=30;
ghpf=1-exp(-d.^2/(2*d0.^2));
%j=ifft2(fftshift(Fi.*ghpf));
j=ifft2(fftshift(Fi.*ghpf));
subplot(4,2,6);imshow(j, []);title('new');
thanks anyway
Clean up your memory. It has to work that I have just tested.
You have another typo:
[x,y,]=meshgrid(1:n,1:m); must be
[x,y]=meshgrid(1:n,1:m);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by