Array dimensions must match for binary array op. How to fix this thanks

These are the codes:
input_image = imread ('C.tif');
[M, N] = size(input_image);
FT_img = fft2(double(input_image));
n = 2;
D0 = 20;
u = 0:(M-1);
v = 0:(N-1);
idx = find(u > M/2);
u(idx) = u(idx) - M;
idy = find(v > N/2);
v(idy) = v(idy) - N;
[V, U] = meshgrid(v, u);
D = sqrt(U.^2 + V.^2);
H = 1./(1 + (D./D0).^(2*n));
G = H.*FT_img;
output_image = real(ifft2(double(G)));
subplot(2, 1, 1), imshow(input_image),
subplot(2, 1, 2), imshow(output_image, [ ]);
the command window shows that:
Array dimensions must match for binary array op.
Error in Run_1 (line 24)
G = H.*FT_img;
I looked up on other people's questions which are similar but i still don't get it so if anyone can fix this for me, that would be greatly appreciated.
Sorry im new and thanks

2 commentaires

Where are you making sure your image is 2D? The tiff format supports a wide range of options, not all of them have only 1 channel. You might need rgb2gray somewhere in there.
Yep i did that and thanks

Connectez-vous pour commenter.

 Réponse acceptée

Ameer Hamza
Ameer Hamza le 1 Déc 2020
Modifié(e) : Ameer Hamza le 1 Déc 2020
Change the line
[M, N] = size(input_image);
to
[M, N] = size(input_image, [1 2]);
Also, instead of
FT_img = fft2(double(input_image));
I recommend using im2double()
FT_img = fft2(im2double(input_image));

5 commentaires

iqbal muzakki
iqbal muzakki le 1 Déc 2020
Modifié(e) : iqbal muzakki le 1 Déc 2020
now it shows this:
Error using size
Too many output arguments.
Error in Run_1 (line 3)
[M, N] = size(input_image, [1 2]);
kinda fixed it now it says :
Array dimensions must match for binary array op.
Error in Run_1 (line 24)
G = H.*FT_img;
Are you using an older release of MATLAB.
In any case, you can replace the line
[M, N] = size(input_image);
with
M = size(input_image, 1);
N = size(input_image, 2);
Im using R2016b version
Phew it works like magic,
Thanks A LOT
Appreciated
I am glad to be of help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Mobile Fundamentals 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!

Translated by