-
Notifications
You must be signed in to change notification settings - Fork 3
/
generate_test.m
63 lines (52 loc) · 1.9 KB
/
generate_test.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
clear; close all;
addpath utils/ ;
%% settings
folder = 'Test/Set5/GT/';
savepath = 'test_x4.h5';
size_input = 11;
size_label = 44;
scale = 4;
stride = 3;
%% initialization
data = zeros(size_input, size_input, 1, 1);
label = zeros(size_label, size_label, 1, 1);
count = 0;
%% generate data
n = dir(fullfile(folder,'*.png'));
for i = 1 : length(n)
disp(['image :' num2str(i)]);
image = imread(fullfile(folder, n(i).name));
image = rgb2ycbcr(image);
image = im2double(image(:, :, 1));
im_label = modcrop(image, scale);
im_input = imresize(im_label, 1/scale, 'bicubic');
[hei,wid] = size(im_input);
for x = 1 : stride : hei - size_input + 1
for y = 1 : stride : wid - size_input + 1
locx = scale * (x + floor((size_input - 1)/2)) - floor((size_label + scale)/2 - 1);
locy = scale * (y + floor((size_input - 1)/2)) - floor((size_label + scale)/2 - 1);
subim_input = im_input(x : size_input + x - 1, y : size_input + y - 1);
subim_label = im_label(locx : size_label + locx - 1, locy : size_label + locy - 1);
count = count + 1;
data(:, :, 1, count) = subim_input;
label(:, :, 1, count) = subim_label;
end
end
end
order = randperm(count);
data = data(:, :, 1, order);
label = label(:, :, 1, order);
%% writing to HDF5
chunksz = 4;
created_flag = false;
totalct = 0;
for batchno = 1:floor(count/chunksz)
last_read = (batchno-1)*chunksz;
batchdata = data(:,:,1,last_read+1:last_read+chunksz);
batchlabs = label(:,:,1,last_read+1:last_read+chunksz);
startloc = struct('dat',[1,1,1,totalct+1], 'lab', [1,1,1,totalct+1]);
curr_dat_sz = store2hdf5(savepath, batchdata, batchlabs, ~created_flag, startloc, chunksz);
created_flag = true;
totalct = curr_dat_sz(end);
end
h5disp(savepath);