-
Notifications
You must be signed in to change notification settings - Fork 8
/
GenerateDataForTest.m
78 lines (66 loc) · 2.64 KB
/
GenerateDataForTest.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
%% Initialization
clear all;
clc;
%close all;
addpath(genpath('./Functions/'))
%% Parameters setting
angRes = 8; % Angular Resolution, options, e.g., 3, 5, 7, 9. Default: 5
factor = 2;
downRatio = 1/factor;
sourceDataPath = '../Datasets/';
sourceDatasets = dir(sourceDataPath);
sourceDatasets(1:2) = [];
datasetsNum = length(sourceDatasets);
idx = 0;
SavePath = ['../Data/Test_', num2str(factor), 'xSR_', num2str(angRes), 'x', num2str(angRes), '/', ];
if exist(SavePath, 'dir')==0
mkdir(SavePath);
end
for DatasetIndex = 1 : 5
DatasetName = sourceDatasets(DatasetIndex).name;
SavePath_dataset = [SavePath, DatasetName];
if exist(SavePath_dataset, 'dir')==0
mkdir(SavePath_dataset);
end
sourceDataFolder = [sourceDataPath, sourceDatasets(DatasetIndex).name, '/test/'];
folders = dir(sourceDataFolder); % list the scenes
if isempty(folders)
continue
end
folders(1:2) = [];
sceneNum = length(folders);
for iScene = 1 : sceneNum
idx_s = 0;
sceneName = folders(iScene).name;
sceneName(end-3:end) = [];
fprintf('Generating test data of Scene_%s in Dataset %s......\n', sceneName, sourceDatasets(DatasetIndex).name);
dataPath = [sourceDataFolder, folders(iScene).name];
data = load(dataPath);
LF = data.LF;
[U, V, H, W, ~] = size(LF);
while mod(H, 4) ~= 0
H = H - 1;
end
while mod(W, 4) ~= 0
W = W - 1;
end
LF = LF(floor((U-angRes+2)/2):floor((U+angRes)/2), floor((V-angRes+2)/2):floor((V+angRes)/2), 1:H, 1:W, 1:3); % Extract central angRes*angRes views
[U, V, H, W, ~] = size(LF);
data = single(zeros(U*H*downRatio, V*W*downRatio));
label = single(zeros(U*H, V*W));
for u = 1 : U
for v = 1 : V
SAI_rgb = squeeze(LF(u, v, :, :, :));
SAI_ycbcr = rgb2ycbcr(double(SAI_rgb));
label((u-1)*H+1 : u*H, (v-1)*W+1 : v*W) = SAI_ycbcr(:, :, 1);
data((u-1)*H*downRatio+1 : u*H*downRatio, (v-1)*W*downRatio+1 : v*W*downRatio) = imresize(SAI_ycbcr(:, :, 1), downRatio);
end
end
SavePath_H5 = [SavePath_dataset, '/', sceneName, '.h5'];
h5create(SavePath_H5, '/data', size(data), 'Datatype', 'single');
h5write(SavePath_H5, '/data', single(data), [1,1], size(data));
h5create(SavePath_H5, '/label', size(label), 'Datatype', 'single');
h5write(SavePath_H5, '/label', single(label), [1,1], size(label));
idx = idx + 1;
end
end