Kernel Matrix apply convolution

13 次查看(过去 30 天)
Patrick Carey
Patrick Carey 2015-4-10
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 个评论
Patrick Carey
Patrick Carey 2015-4-10
Also none of these functions are allowed: conv, conv2, convmtx, convn, deconv, filter, xcorr
Tim Harrell
Tim Harrell 2021-9-17
sum(sum(kernal.......
spelling ?

请先登录,再进行评论。

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by