Convolution (Matrix Multiplication)

조회 수: 22 (최근 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by