multiplying a weight mask with input matrix

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by