-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interp_Stage1_ICASSP2019.m
84 lines (84 loc) · 3.53 KB
/
Interp_Stage1_ICASSP2019.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
80
81
82
83
84
function yHR=Interp_Stage1_ICASSP2019(yLR,n,W,K,lambda,sigma,cw)
y=Image_Extend(yLR,n/2);
N_m=size(y,1)*2;
N_n=size(y,2)*2;
index_store
yPre=bicubic_interp(y);
ff=fspecial('gaussian',9,sigma);
gg=Image_Crop(imfilter(Image_Extend(yLR,9),ff),9);
yPre_LR=bicubic_interp(Image_Extend(gg,n/2));
inddd=1:(N_m/2-n/2+1)*(N_n/2-n/2+1);
[xx_LR,yy_LR]=ind2sub([N_m/2-n/2+1 N_n/2-n/2+1],inddd);
xx=xx_LR*2-1;
yy=yy_LR*2-1;
ind_2x=sub2ind([N_m-n+1 N_n-n+1],xx,yy);
MAX_L=ceil((2*W+1)^2/4);
HRPatch_Hat=zeros(n^2,(N_n/2-n/2+1)*(N_m/2-n/2+1),'single');
HRPatch =single(im2col(yPre ,[n n],'sliding'));
HRPatch_LP =single(im2col(yPre_LR,[n n],'sliding'));
HRPatch_b_LP_source =HRPatch_LP(:,ind_2x);
QQ=zeros(n,n);QQ(1:2:end,1:2:end)=1;IND_OO=find(QQ==1);
QQ=zeros(n,n);QQ(2:2:end,2:2:end)=1;IND_EE=find(QQ==1);
QQ=zeros(n,n);QQ(2:2:end,1:2:end)=1;IND_EO=find(QQ==1);
QQ=zeros(n,n);QQ(1:2:end,2:2:end)=1;IND_OE=find(QQ==1);
parfor ind=1:(N_m/2-n/2+1)*(N_n/2-n/2+1)
[xx_LR,yy_LR]=ind2sub([N_m/2-n/2+1 N_n/2-n/2+1],ind);
xx=xx_LR*2-1;
yy=yy_LR*2-1;
[x_min,x_max,y_min,y_max]=Border_Return(xx,yy,N_m,N_n,n,W);
Search_Coord_EO=zeros(MAX_L,1,'uint32');
Search_Coord_OE=zeros(MAX_L,1,'uint32');
Search_Coord_EE=zeros(MAX_L,1,'uint32');
[yyy,xxx]=meshgrid(y_min+1:2:y_max,x_min:2:x_max);
Search_Coord_OE(1:(W+1)*W)=(yyy(:)-1)*(N_m-n+1)+xxx(:);
[yyy,xxx]=meshgrid(y_min:2:y_max,x_min+1:2:x_max);
Search_Coord_EO(1:(W+1)*W)=(yyy(:)-1)*(N_m-n+1)+xxx(:);
[yyy,xxx]=meshgrid(y_min+1:2:y_max,x_min+1:2:x_max);
Search_Coord_EE(1:W^2) =(yyy(:)-1)*(N_m-n+1)+xxx(:);
b_LR=HRPatch_b_LP_source(:,ind);
UPDATE_OE=weight_return(b_LR,HRPatch,HRPatch_LP,cw,Search_Coord_OE,K,IND_OE,IND_OO,lambda);
UPDATE_EO=weight_return(b_LR,HRPatch,HRPatch_LP,cw,Search_Coord_EO,K,IND_EO,IND_OO,lambda);
UPDATE_EE=weight_return(b_LR,HRPatch,HRPatch_LP,cw,Search_Coord_EE,K,IND_EE,IND_OO,lambda);
Y_OE_HRPatch=zeros(n,n);
Y_OE_HRPatch(IND_OE)=UPDATE_OE;
%=====
Y_EO_HRPatch=zeros(n,n);
Y_EO_HRPatch(IND_EO)=UPDATE_EO;
%======
Y_EE_HRPatch=zeros(n,n);
Y_EE_HRPatch(IND_EE)=UPDATE_EE;
%======
yPatch_Hat=Y_OE_HRPatch+Y_EO_HRPatch+Y_EE_HRPatch;
yPatch_Hat(yPatch_Hat>+255)=+255;
yPatch_Hat(yPatch_Hat< 0)= 0;
%=======
HRPatch_Hat(:,ind)=yPatch_Hat(:);
end
% ======
y_Hat=zeros(N_m,N_n);
Weight=zeros(N_m,N_n);
for ind=1:(N_m/2-n/2+1)*(N_n/2-n/2+1)
[xx_LR,yy_LR]=ind2sub([N_m/2-n/2+1 N_n/2-n/2+1],ind);
patch=reshape(HRPatch_Hat(:,ind),[n n]);
r=xx_LR*2-1;
c=yy_LR*2-1;
y_Hat(r:r+n-1,c:c+n-1)= y_Hat(r:r+n-1,c:c+n-1)+patch;
Weight(r:r+n-1,c:c+n-1)=Weight(r:r+n-1,c:c+n-1)+1;
end
y_Hat=y_Hat./Weight;
yPre=y_Hat;
t=Image_Crop(yPre,n);
t(1:2:end,1:2:end)=yLR;
yHR=t;
end
function UPDATE=weight_return(b_LR,HRPatch,HRPatch_LP,cw,SearchAreaCoord,K,IND_UPDATE,IND_OO,lambda)
s=SearchAreaCoord(SearchAreaCoord>0);
PATCHES = HRPatch_LP(:,s);
PATCHES_ORI = HRPatch(:,s);
ddd=-vecnorm(b_LR-PATCHES,1);
[dddd,ind]=maxk(ddd,K);
X=PATCHES(:,ind);
dddd=exp(dddd(1:K)/cw);
Core=X(IND_OO,:).'*X(IND_OO,:)+lambda*diag(dddd(1)./dddd(:)); %% some room to accelerate the operation.
UPDATE=PATCHES_ORI(IND_UPDATE,ind)*(Core\(X(IND_OO,:).'*b_LR(IND_OO)));
end