📄 convolution2d.m
字号:
in=[0 0 0 0 0 0 ;
0 0 0 0 0 1;
0 0 0 0 1 1];
kernel=[0 0 0;
0 0 1;
0 1 1];
% in=in';
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+kCenterX %// rows
for j=1:1:cols+kCenterY
sum = 0;
out(i,j)=0;
for m=1:1:kRows
mm = kRows - m+1;
for n=1:1:kCols
nn = kCols - n+1;
%// 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -