Array dimensions must match for binary array op.

%b
lake=imread('lake.tif');
lake_fft=fftshift(fft2(lake));
[M,N]=size(lake_fft);
lap_filt=zeros(M,N);
for i=1:M
for j=1:N
lap_filt(i,j)= -4*pi^2*((i-M/2)^2+(j-N/2)^2);
end
end
lake_fft=lake_fft.*lap_filt;
lake_reconstruct=ifft2(ifftshift(lake_fft));
figure(1)
subplot(1,2,1);imshow(lake);title('Original Image')
subplot(1,2,2);imshow(lake_reconstruct,[]);title('Laplace frequency')
Im getting the following errors:
Array dimensions must match for binary array op.
(line 12)
lake_fft=lake_fft.*lap_filt;
not sure what the problem is and how it can be solved
whos lakess
Name Size Bytes Class Attributes
lakess 512x512x2 524288 uint8

2 件のコメント

Cris LaPierre
Cris LaPierre 2020 年 9 月 26 日
No idea what lakess is. It's not used in your code.
Kat_33
Kat_33 2020 年 9 月 26 日
yeah its the same as lake in my code

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

 採用された回答

Cris LaPierre
Cris LaPierre 2020 年 9 月 26 日

0 投票

The code runs just find for me. I don't have 'lake.tif', but I don't think that should matter.
Try clearing your workspace or restarting MATLAB.

5 件のコメント

Kat_33
Kat_33 2020 年 9 月 26 日
I did but I'm stil getting the same issue. Think the problem is with the lake image since I deleted all my code and just tried to output it but it would still show me errors like this:
Multi-plane image inputs must be RGB images of size MxNx3.
Cris LaPierre
Cris LaPierre 2020 年 9 月 26 日
Consider attaching the image to your post then. Use the paper clip icon.
Kat_33
Kat_33 2020 年 9 月 26 日
solved the problem, just had to change the dimensions of the image using
lake=lake[:,:,1];
Cris LaPierre
Cris LaPierre 2020 年 9 月 26 日
Your image seems to have an unexpected 3rd dimension. I plot both below. All values in the second "sheet" are 255, resulting in a white image (hard to see that here since the page is white). I think you can ignore the second sheet.
lake = lake(:,:,1);
Here are the images:
imshow(lake(:,:,1))
imshow(lake(:,:,2))
Kat_33
Kat_33 2020 年 9 月 26 日
that makes sense, thank you very much!

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

その他の回答 (0 件)

カテゴリ

製品

リリース

R2020b

タグ

質問済み:

2020 年 9 月 26 日

コメント済み:

2020 年 9 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by