Kernel Matrix apply convolution

조회 수: 13 (최근 30일)
Patrick Carey
Patrick Carey 2015년 4월 10일
댓글: Tim Harrell 2021년 9월 17일
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개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by