-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathEstDefocusFilterUnc.m
55 lines (49 loc) · 1.35 KB
/
EstDefocusFilterUnc.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
function Res = EstDefocusFilterUnc(ImageDepthSet, params, filterBankSize)
% ImageDepthSet is the set of defocused image patches
% of the form A' * A where A is the convolution matrix for an image.
lambda = 1e5;
if(isfield(params, 'lambda'))
lambda = params.lambda;
end
NFilters = 1;
if(isfield(params, 'NFilters'))
NFilters = params.NFilters;
end
if(~exist('filterBankSize', 'var'))
filterBankSize = 2;
end
NDepth = length(ImageDepthSet);
MatSize = size(ImageDepthSet{1,1}, 1);
KSize = sqrt(MatSize/filterBankSize);
Q = [];
Filters = cell(NDepth, filterBankSize * NFilters);
for idx = 1:NDepth
AA = NDepth * lambda * ImageDepthSet{idx};
for idx2 = 1:NDepth
if(idx ~= idx2)
AA = AA - ImageDepthSet{idx2};
end
end
if(idx == 1)
Q = blkdiag(sparse(AA));
else
Q = blkdiag(Q, sparse(AA));
end
end
[U, S, V] = svd(full(Q)); %svds(Q, 1, 0);
for idxFilter = NFilters:-1:1
for idx = 1:NDepth
StartIdx = (idx - 1) * MatSize;
IDX = StartIdx + (1:MatSize);
F = V(IDX, idxFilter);
f1 = reshape(F(1:KSize * KSize), KSize, KSize);
f2 = reshape(F(KSize * KSize + 1:end), KSize, KSize);
Filters{idx, 1 + 2*(idxFilter - 1)} = f1;
Filters{idx, 2 + 2*(idxFilter - 1)} = f2;
end
end
Res.Filters = Filters;
Res.Q = Q;
Res.U = U;
Res.S = S;
Res.V = V;