please help>>>how to fix (Matrix dimensions must agree.) error in matlab?
古いコメントを表示
how to fix (Matrix dimensions must agree.) error in matlab?
my code is:
a=imread('lena.bmp');
I=im2double(a);
H=fspecial('log',5);
%convolution
[r,c]=size(I);
for y=2:r-1
for x=2 :c-1
windowI= I(y:y+3 , x: x+3);
windowH= H(y:y+1 , x: x+1);
IH= sum(sum(windowI .* windowH));
end
end
figure(2);
imshow (IH) ;
i think this line: IH= sum(sum(windowI .* windowH)); causes the error but how to fix it?
回答 (3 件)
Walter Roberson
2013 年 11 月 14 日
0 投票
Why are you expecting that a matrix that is 4 x 4 can be multiplied by a matrix that is 2 x 2 ?
4 件のコメント
Walter Roberson
2013 年 11 月 14 日
What is the intent? To tile the 2 x 2 into a 4 x 4 and then multiply?
Walter Roberson
2013 年 11 月 15 日
Perhaps you should be using conv2() ?
Youssef Khmou
2013 年 11 月 15 日
編集済み: Youssef Khmou
2013 年 11 月 15 日
hi Asma,
the number of columns of WindowI must be the same as the number of lines in WindowH, take the two blocks with same dimensions or try :
a=imread('circuit.tif');
I=im2double(a);
H=fspecial('log',5);
[r,c]=size(I);
a=1;b=1;
for x=1:r-5 % ver
for y=1:c-4
windowI= I(x:x+4 , y: y+4);
%windowH= H(x:x+3 , y: y+1);
IH(x,y)= sum(sum(windowI .* H)); % element wise or matrix product????????
end
end
figure(2); imshow (IH)
2 件のコメント
Asma
2013 年 11 月 15 日
Asma
2013 年 11 月 15 日
0 投票
1 件のコメント
Youssef Khmou
2013 年 11 月 15 日
the size of windowI depends on H, as you fspecal is 5x5 then a window must have the size 5*m , for arbitrary m, try the example i posted
カテゴリ
ヘルプ センター および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!