-
Notifications
You must be signed in to change notification settings - Fork 119
/
SR_LapSRN.m
69 lines (56 loc) · 1.68 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
66
67
68
69
function [img_HR, time] = SR_LapSRN(img_LR, net, scale, gpu)
% -------------------------------------------------------------------------
% Description:
% function to apply SR with LapSRN
%
% Input:
% - img_LR: low-resolution image
% - net : LapSRN model
% - scale : upsampling scale
% - gpu : GPU ID
%
% 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
% wlai24@ucmerced.edu
% 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( gpu )
y = gpuArray(y);
end
% bicubic upsample UV
img_HR = imresize(img_LR, scale);
% forward
tic;
inputs = {'LR', y};
net.eval(inputs);
time = toc;
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