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

조회 수: 4 (최근 30일)
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.

댓글을 달려면 로그인하십시오.

채택된 답변

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일
Phew it works like magic,
Thanks A LOT
Appreciated

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by