Sum particular adjacent elements
Mostrar comentarios más antiguos
I learned about conv2 from the the post:
My original goal was to sum all the adjacent elements in a matrix. The solution using conv2, from the post above, with the mask:
msk_0 = [1 1 1; 1 0 1; 1 1 1]
worked well.
Using conv2, with a similar logic, now I want to sum the elements above and adjacent to a given element. In this case my mask becomes:
msk_1 = [1 1 1; 0 0 0; 0 0 0] %top
I want to run this on a matrix f, indentical to the mask.
f = [1 1 1; 0 0 0; 0 0 0]
The answer produced is 0
>> conv2(f, msk_1, 'same')
ans =
0 0 0
0 0 0
0 0 0
My expectation was that the mask would result in the sum of the elements above and adjacent to a given element in f. The result in this case would be:
0 0 0
2 3 2
0 0 0
What is it I am missing about the functionality of conv2?
How do I achieve my goal of summing only the specific elements in a given mask?
Thanks for your input.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Correlation and Convolution en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!