convolution2d.asv
来自「convolution with matlab」· ASV 代码 · 共 31 行
ASV
31 行
in=[0 0 0 0 0 0 ;0 0 0 1 0 0;0 0 0 0 0 0];
kernel=[1 0;0 0];
rows=size(in,1);
cols=size(in,2);
kRows=size(kernel,1);
kCols=size(kernel,2);
% find center position of kernel (half of kernel size)
kCenterX = uint16(kCols / 2;
kCenterY = uint16(kRows / 2;
for i=1:1:rows %// rows
for j=1:1:cols
sum = 0;
out(i,j)=0;
for m=1:1:kRows
mm = kRows - 1 - m;
for n=1:1:kCols
nn = kCols - 1 - n;
%// index of input signal, used for checking boundary
ii = i + (m - kCenterY);
jj = j + (n - kCenterX);
%// ignore input samples which are out of bound
if (ii >= 1) && (ii <= rows) && (jj >= 1) && (jj <= cols)
out(i,j) =out(i,j)+ in(ii,jj) * kernel(mm,nn);
end
end
end
end
end
[out]
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?