-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathDataset_generator.m
172 lines (139 loc) · 5.12 KB
/
Dataset_generator.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
clc
clear all
close all
% create Train_data and Test_data directories
mkdir Train_Data
mkdir Test_Data
addpath('Train_References'); % change the path if the Reference frames are not in the default directory
addpath('Train_Data');
addpath('Test_Data');
n=60; %Train dataset
SubsetSize = 256;
parfor img = 1:363
name_image = sprintf('Ref%01d.tif',img);
Image_Ref = double(imread(name_image));
Image_Ref_interpol = zeros(SubsetSize+3,SubsetSize+3); % add padding of 0 for interpolation window 4x4 and translation [-1,1]
Image_Ref_interpol(2:SubsetSize+1,2:SubsetSize+1)= Image_Ref;
xp=[1:SubsetSize] + 1;
yp=[1:SubsetSize] + 1;
xxp=1:SubsetSize + 3;
yyp=1:SubsetSize + 3;
[Xp_subset,Yp_subset] = meshgrid(xp,yp);
% Define the regions size
for l = 1:n
if l <11 % l==1
s = 128;
elseif l<21 % l==2
s = 64;
elseif l<31 % l==3
s = 32;
elseif l<41 % l==4
s = 16;
elseif l<51 % l==5
s = 8;
else
s = 4;
end
xp0=[1:1/s:SubsetSize/s+1-1/s]+2;
yp0=[1:1/s:SubsetSize/s+1-1/s]+2;
xxp0=1:(SubsetSize/s)+3;
yyp0=1:(SubsetSize/s)+3;
[Xp_subset0,Yp_subset0] = meshgrid(xp0,yp0);
% A random displamcent for each region
f = randi([-100 100],SubsetSize/s+3,SubsetSize/s+3)/115;
g = randi([-100 100],SubsetSize/s+3,SubsetSize/s+3)/115;
% Bicubic interpolation between the randoom displacments
x0 = Xp_subset0 ;
y0 = Yp_subset0 ;
disp_x = interp2(xxp0,yyp0,f,x0,y0,'cubic');
disp_y = interp2(xxp0,yyp0,g,x0,y0,'cubic');
% Setting the boundries dispalcements to 0
disp_x(1:2,:) = 0;
disp_y(1:2,:) = 0;
disp_x(:,1:2) = 0;
disp_y(:,1:2) = 0;
disp_x(SubsetSize-1:SubsetSize,:) = 0;
disp_y(SubsetSize-1:SubsetSize,:) = 0;
disp_x(:,SubsetSize-1:SubsetSize) = 0;
disp_y(:,SubsetSize-1:SubsetSize) = 0;
% Generate the deformed image based on bi-cubic interpolation
x = Xp_subset + disp_x;
y = Yp_subset + disp_y;
Image_BD = interp2(xxp,yyp,Image_Ref_interpol,x,y,'cubic');
% Data labels
name_ref = sprintf('Train_Data/Ref%03d_%02d.csv',img,l);
name_def = sprintf('Train_Data/Def%03d_%02d.csv',img,l);
name_dispx = sprintf('Train_Data/Dispx%03d_%02d.csv',img,l);
name_dispy = sprintf('Train_Data/Dispy%03d_%02d.csv',img,l);
% Write the data
dlmwrite(name_ref, Image_Ref, 'delimiter', ',', 'precision', '%.0f');
dlmwrite(name_def, Image_BD, 'delimiter', ',', 'precision', '%.3f');
dlmwrite(name_dispx, disp_x, 'delimiter', ',', 'precision', '%.3f');
dlmwrite(name_dispy, disp_y, 'delimiter', ',', 'precision', '%.3f');
end
end
%Test dataset
n=6;
parfor img = 1:363
name_image = sprintf('Ref%01d.tif',img);
Image_Ref = double(imread(name_image));
Image_Ref_interpol = zeros(SubsetSize+3,SubsetSize+3); % add padding of 0 for interpolation window 4x4 and translation [-1,1]
Image_Ref_interpol(2:SubsetSize+1,2:SubsetSize+1)= Image_Ref;
xp=[1:SubsetSize] + 1;
yp=[1:SubsetSize] + 1;
xxp=1:SubsetSize + 3;
yyp=1:SubsetSize + 3;
[Xp_subset,Yp_subset] = meshgrid(xp,yp);
% Define the regions size
for l = 1:n
if l <11 % l==1
s = 128;
elseif l<21 % l==2
s = 64;
elseif l<31 % l==3
s = 32;
elseif l<41 % l==4
s = 16;
elseif l<51 % l==5
s = 8;
else
s = 4;
end
xp0=[1:1/s:SubsetSize/s+1-1/s]+2;
yp0=[1:1/s:SubsetSize/s+1-1/s]+2;
xxp0=1:(SubsetSize/s)+3;
yyp0=1:(SubsetSize/s)+3;
[Xp_subset0,Yp_subset0] = meshgrid(xp0,yp0);
% A random displamcent for each region
f = randi([-100 100],SubsetSize/s+3,SubsetSize/s+3)/115;
g = randi([-100 100],SubsetSize/s+3,SubsetSize/s+3)/115;
% Bicubic interpolation between the randoom displacments
x0 = Xp_subset0 ;
y0 = Yp_subset0 ;
disp_x = interp2(xxp0,yyp0,f,x0,y0,'cubic');
disp_y = interp2(xxp0,yyp0,g,x0,y0,'cubic');
% Setting the boundries dispalcements to 0
disp_x(1:2,:) = 0;
disp_y(1:2,:) = 0;
disp_x(:,1:2) = 0;
disp_y(:,1:2) = 0;
disp_x(SubsetSize-1:SubsetSize,:) = 0;
disp_y(SubsetSize-1:SubsetSize,:) = 0;
disp_x(:,SubsetSize-1:SubsetSize) = 0;
disp_y(:,SubsetSize-1:SubsetSize) = 0;
% Generate the deformed image based on bi-cubic interpolation
x = Xp_subset + disp_x;
y = Yp_subset + disp_y;
Image_BD = interp2(xxp,yyp,Image_Ref_interpol,x,y,'cubic');
% Data labels
name_ref = sprintf('Test_Data/Ref%03d_%02d.csv',img,l);
name_def = sprintf('Test_Data/Def%03d_%02d.csv',img,l);
name_dispx = sprintf('Test_Data/Dispx%03d_%02d.csv',img,l);
name_dispy = sprintf('Test_Data/Dispy%03d_%02d.csv',img,l);
% Write the data
dlmwrite(name_ref, Image_Ref, 'delimiter', ',', 'precision', '%.0f');
dlmwrite(name_def, Image_BD, 'delimiter', ',', 'precision', '%.3f');
dlmwrite(name_dispx, disp_x, 'delimiter', ',', 'precision', '%.3f');
dlmwrite(name_dispy, disp_y, 'delimiter', ',', 'precision', '%.3f');
end
end