フィルターのクリア

Sum particular adjacent elements

2 ビュー (過去 30 日間)
ASC
ASC 2020 年 7 月 18 日
コメント済み: ASC 2020 年 7 月 19 日
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.

採用された回答

Image Analyst
Image Analyst 2020 年 7 月 18 日
No, you don't understand what convolution is. With convolution, the kernel gets flipped top-to-bottom, and left-to-right. There are mathematical reasons for this based on linear systems theory. So if you want the sum of the above row, your kernel would have to be
msk_1 = [0 0 0; 0 0 0; 1 1 1] %top
Or you can use imfilter() and not flip the mask because imfilter() does not flip the mask.
  1 件のコメント
ASC
ASC 2020 年 7 月 19 日
Thanks so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by