フィルターのクリア

multiplying a weight mask with input matrix

2 ビュー (過去 30 日間)
Anusha
Anusha 2014 年 10 月 31 日
回答済み: Mohammad Abouali 2014 年 10 月 31 日
Hi, i am trying to find a way to calculate sum(w(i,j)*A(m+i,n+j)) where w is a 3x3 weight mask , A is the input matrix,m & n size of A,i & j size of w. i have written a function to do this.
if true
% code
function Y = myfun (m,n)
A=imread('');
c=0;
for i=1:3
for j =1:3
c=c+A(m+i,n+j)*B(i,j);
end
end
Y=c;
end
end
and a loop to store the values in a matrix C .
if true
% code
[x,y]=size(A);
for m=1:x
for n=1:y
C(m,n)=myfun(m,n);
end
end
end
But i am getting an index out of bound error. i have considered padding the input matrix but it will change the parameters being passed. Please help me solve this.

採用された回答

Mohammad Abouali
Mohammad Abouali 2014 年 10 月 31 日
use conv2 function
That will get the job done much faster.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by