forked from phoenix104104/LapSRN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SR_LapSRN.m
65 lines (53 loc) · 1.64 KB
/
SR_LapSRN.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
function img_HR = SR_LapSRN(img_LR, net, opts)
% -------------------------------------------------------------------------
% Description:
% function to apply LapSRN
%
% Input:
% - img_LR: low-resolution image
% - net : LapSRN model
% - opts : options generated from init_opts()
%
% Output:
% - img_HR: high-resolution image
%
% Citation:
% Deep Laplacian Pyramid Networks for Fast and Accurate Super-Resolution
% Wei-Sheng Lai, Jia-Bin Huang, Narendra Ahuja, and Ming-Hsuan Yang
% IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2017
%
% Contact:
% Wei-Sheng Lai
% University of California, Merced
% -------------------------------------------------------------------------
%% setup
net.mode = 'test' ;
output_var = 'level1_output';
output_index = net.getVarIndex(output_var);
net.vars(output_index).precious = 1;
% RGB to YUV
if( size(img_LR, 3) > 1 )
img_LR = rgb2ycbcr(img_LR);
end
% extract Y
y = single(img_LR(:, :, 1));
if( opts.gpu )
y = gpuArray(y);
end
% bicubic upsample UV
img_HR = imresize(img_LR, opts.scale);
% forward
inputs = {'LR', y};
net.eval(inputs);
y = gather(net.vars(output_index).value);
% resize if size does not match the output image
if( size(y, 1) ~= size(img_HR, 1) )
y = imresize(y, [size(img_HR, 1), size(img_HR, 2)]);
end
img_HR(:, :, 1) = double(y);
% YUV to RGB
if( size(img_HR, 3) > 1 )
img_HR = ycbcr2rgb(img_HR);
end
end