-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscbp.m
79 lines (59 loc) · 2.12 KB
/
scbp.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function [hIm] = scbp(lIm, up_scale, Dh, Dl, lambda, overlap, M)
%M: mapping function from Dl to Dh
% normalize the dictionary
norm_Dl = sqrt(sum(Dl.^2, 1));
Dl = Dl./repmat(norm_Dl, size(Dl, 1), 1);
patch_size = sqrt(size(Dh, 1));
% bicubic interpolation of the low-resolution image
mIm = single(imresize(lIm, up_scale, 'bicubic'));
hIm = zeros(size(mIm));
cntMat = zeros(size(mIm));
[h, w] = size(mIm);
% extract low-resolution image features
lImfea = extr_lIm_fea(mIm);
% patch indexes for sparse recovery (avoid boundary)
gridx = 3:patch_size - overlap : w-patch_size-2;
gridx = [gridx, w-patch_size-2];
gridy = 3:patch_size - overlap : h-patch_size-2;
gridy = [gridy, h-patch_size-2];
A = Dl'*Dl;
cnt = 0;
% loop to recover each low-resolution patch
for ii = 1:length(gridx),
for jj = 1:length(gridy),
cnt = cnt+1;
xx = gridx(ii);
yy = gridy(jj);
mPatch = mIm(yy:yy+patch_size-1, xx:xx+patch_size-1);
mMean = mean(mPatch(:));
mPatch = mPatch(:) - mMean;
mNorm = sqrt(sum(mPatch.^2));
mPatchFea = lImfea(yy:yy+patch_size-1, xx:xx+patch_size-1, :);
mPatchFea = mPatchFea(:);
mfNorm = sqrt(sum(mPatchFea.^2));
if mfNorm > 1,
y = mPatchFea./mfNorm;
else
y = mPatchFea;
end
b = -Dl'*y;
% sparse recovery
wl = L1QP_FeatureSign_yang(lambda, A, b);
wh = M*wl;% mapping from sl to sh
Z= (wl~=0);
wh=wh.*Z;
% generate the high resolution patch and scale the contrast
hPatch = Dh*wh;
hPatch = lin_scale(hPatch, mNorm);
hPatch = reshape(hPatch, [patch_size, patch_size]);
hPatch = hPatch + mMean;
hIm(yy:yy+patch_size-1, xx:xx+patch_size-1) = hIm(yy:yy+patch_size-1, xx:xx+patch_size-1) + hPatch;
cntMat(yy:yy+patch_size-1, xx:xx+patch_size-1) = cntMat(yy:yy+patch_size-1, xx:xx+patch_size-1) + 1;
end
end
% fill in the empty with bicubic interpolation
idx = (cntMat < 1);
hIm(idx) = mIm(idx);
cntMat(idx) = 1;
hIm = hIm./cntMat;
hIm = uint8(hIm);