Kernel Matrix apply convolution
4 views (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!