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

4 views (last 30 days)
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 Comments
Rik
Rik on 1 Dec 2020
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.

Sign in to comment.

Accepted Answer

Ameer Hamza
Ameer Hamza on 1 Dec 2020
Edited: Ameer Hamza on 1 Dec 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 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!