forked from xiaolin-han/OTD-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSet_blur_matrix.m
62 lines (47 loc) · 1.71 KB
/
Set_blur_matrix.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function A = Set_blur_matrix( par )
s = par.scale;
[lh lw ch] = size( par.LR );
hh = lh*s;
hw = lw*s;
M = lh*lw;
N = hh*hw;
ws = size( par.psf, 1 );
t = (ws-1)/2;
cen = ceil(ws/2);
ker = par.psf;
nv = ws*ws;
nt = (nv)*M;
R = zeros(nt,1);
C = zeros(nt,1);
V = zeros(nt,1);
cnt = 1;
pos = (1:hh*hw);
pos = reshape(pos, [hh hw]);
for lrow = 1:lh
for lcol = 1:lw
row = (lrow-1)*s + 1;
col = (lcol-1)*s + 1;
row_idx = (lcol-1)*lh + lrow;
rmin = max( row-t, 1);
rmax = min( row+t, hh);
cmin = max( col-t, 1);
cmax = min( col+t, hw);
sup = pos(rmin:rmax, cmin:cmax);
col_ind = sup(:);
r1 = row-rmin;
r2 = rmax-row;
c1 = col-cmin;
c2 = cmax-col;
ker1 = ker(cen-r1:cen+r2, cen-c1:cen+c2);
ker2 = ker1(:);
nn = size(col_ind,1);
R(cnt:cnt+nn-1) = row_idx;
C(cnt:cnt+nn-1) = col_ind;
V(cnt:cnt+nn-1) = ker2;
cnt = cnt + nn;
end
end
R = R(1:cnt-1);
C = C(1:cnt-1);
V = V(1:cnt-1);
A = sparse(R, C, V, M, N);