Matrix convolution only on some elements
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
KRISTIAN MARCON
am 5 Sep. 2022
Kommentiert: KRISTIAN MARCON
am 6 Sep. 2022
Hi, I'm a junior with matlab experience. I tried to search whatever like my problem on internet without find any answer. I have to do a convolution on a matrix A using conv2 but only if the central element (overlaped on the mask) is 1
For example
A=[ 1 0 1 0 ; 0 1 0 0 ; 1 0 0 0 ; 0 1 0 0]
F=[1 1 1; 1 0 1; 1 1 1]
The convolution conv2(A,F,'same') have to been made only if the central element is 1 (like 1', 3', 5',... elements) skipping the convolution if is 0. Obvious i can accept any other functions like conv2 to do the convolution. Thanks if everybody can help me
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 5 Sep. 2022
Try this:
A=[ 1 0 1 0 ; 0 1 0 0 ; 1 0 0 0 ; 0 1 0 0]
F=[1 1 1; 1 0 1; 1 1 1]
% Do the complete convolution.
AF = conv2(A, F, 'same')
% Since we want the convolution ONLY where A == 1,
% we can replace ONLY those places with AF
Aout = A; % Initialize
mask = A == 1
Aout(mask) = AF(mask) % Replace with AF but only where A is 1.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!