Convolution (Matrix Multiplication)

33 ビュー (過去 30 日間)
Mark Wood
Mark Wood 2021 年 5 月 24 日
編集済み: Image Analyst 2021 年 5 月 24 日
How I want to mutliply one matrix in such way that, For eg,
Given a 5x5 Matrix,
And another 3x3 Matrix,
Mutiply this 3x3 Matrix with 5x5 Matrix such that our resultant matrix look as
Resultant Matrix :
Such That Value of a1 = 31(-1) + 41(-1) + 61(-1) + 71(0) + 41(0) + 71(0) + 71(1) + 61(1) + 41(1) = 40
Value of a2 = 41(-1) + 61(-1) + 71(-1) + 41(0) + 71(0) + 81(0) + 61(1) + 41(1) + 91(1) = 20
Value of a3 = 61(-1) + 71(-1) + 41(-1) + 71(0) + 81(0) + 41(0) + 41(1) + 91(1) + 31(1) = -10
Value of b1 = 71(-1) + 41(-1) + 71(-1) + 71(0) + 61(0) + 41(0) + 31(1) + 31(1) + 51(1) = -70
Similarily we can find all elements of Resultant Matrix
So, Our Resultant Matrix is:
Please help with MATLAB Code of a general case that is valid for all dimensions of both the Matrix.
For e.g., If our given matrix is of 5x5, and our multiplying matrix is of 4x4, then our resultant would become 2x2
Another example, If our given matrix is 6x6, and our multiplying matrix is of 3x3, then our resultant would become 4x4.

回答 (2 件)

David Hill
David Hill 2021 年 5 月 24 日
newMatrix=-conv2(a,b,'valid');

Image Analyst
Image Analyst 2021 年 5 月 24 日
編集済み: Image Analyst 2021 年 5 月 24 日
Try conv2()
output = conv2(m1, m2, 'valid');
Your demo is either showing correlation (not convolution) or else it's showing you happens after the kernel is already flipped. If you're not getting what you want then try imfilter()
output = imfilter(m1, m2, 'valid');
or try to flip the kernel
output conv2(m1, flipud(fliplr(m2)), 'valid');

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by