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 件のコメント

Rik
Rik 2020 年 12 月 1 日
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.
iqbal muzakki
iqbal muzakki 2020 年 12 月 1 日
Yep i did that and thanks

サインインしてコメントする。

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 12 月 1 日
編集済み: Ameer Hamza 2020 年 12 月 1 日
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 件のコメント

iqbal muzakki
iqbal muzakki 2020 年 12 月 1 日
編集済み: iqbal muzakki 2020 年 12 月 1 日
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;
Ameer Hamza
Ameer Hamza 2020 年 12 月 1 日
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);
iqbal muzakki
iqbal muzakki 2020 年 12 月 1 日
Im using R2016b version
iqbal muzakki
iqbal muzakki 2020 年 12 月 1 日
Phew it works like magic,
Thanks A LOT
Appreciated
Ameer Hamza
Ameer Hamza 2020 年 12 月 1 日
I am glad to be of help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by