-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvolution_f1.m
29 lines (26 loc) · 1.1 KB
/
convolution_f1.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
% --- convolution 2d ---
% mention <m> is from 1 to 28-5+1:
% this means that this conv is like:
% x x x x x o o o x x
% x x x x x o o o x x m x x
% primary img: x x x x x conv kernel: o o o x x -> x x x ...
% x x x x x x x x x x x x x
% x x x x x x x x x x
%
% but not like: then m from 1 to 28
% o o o
% x x x x x o o o x x x m x x x x
% x x x x x o o o x x x x x x x x
% primary img: x x x x x conv kernel: x x x x x -> x x x x x ...
% x x x x x x x x x x x x x x x
% x x x x x x x x x x x x x x x
% --- computing convolution results ---
function [state] = convolution(data, kernel)
[data_row,data_col] = size(data);
[kernel_row,kernel_col] = size(kernel);
for m=1:data_col-kernel_col+1
for n=1:data_row-kernel_row+1
state(m,n) = sum(sum(data(m:m+kernel_row-1, n:n+kernel_col-1).*kernel));
end
end
end