Kernel Matrix apply convolution

13 visualizzazioni (ultimi 30 giorni)
Patrick Carey
Patrick Carey il 10 Apr 2015
Commentato: Tim Harrell il 17 Set 2021
I believe I am close to the correct answer for this problem. The question basically is to apply convolution to a numeric matrix A and the kernel matrix. Conditions are the kernel matrix must be normalised before it can be used, dividing each element of the kernel by the sum of all the elements of the kernel (I've done that properly already I think). Need to calculate the margin that needs to be left at the beginning and end of each for loop(which I believe is 3), ensuring that the kernel martix passes over every element of A without going out of bounds. Here is my script so far, as I said before I think I'm close:
function [ B ] = kernelSmooth( A, kernel )
B=zeros(7,7);
nkernel = kernel./(sum(sum(kernal)));
for row = 1:size(A,1)-3
for col = 1:kernel-3
tmpMat= B(row-3:row+3,col-3:col+3) .* nkernel;
B(row,column) = sum(sum(tmpMat,3),1);
end
end
Help is appreciated, i have already spent a fair bit of time on this question
  2 Commenti
Patrick Carey
Patrick Carey il 10 Apr 2015
Also none of these functions are allowed: conv, conv2, convmtx, convn, deconv, filter, xcorr
Tim Harrell
Tim Harrell il 17 Set 2021
sum(sum(kernal.......
spelling ?

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by