Borrar filtros
Borrar filtros

multiplying a weight mask with input matrix

2 visualizaciones (últimos 30 días)
Anusha
Anusha el 31 de Oct. de 2014
Respondida: Mohammad Abouali el 31 de Oct. de 2014
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.

Respuesta aceptada

Mohammad Abouali
Mohammad Abouali el 31 de Oct. de 2014
use conv2 function
That will get the job done much faster.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by