-
Notifications
You must be signed in to change notification settings - Fork 25
/
Dataset_generator.m
147 lines (114 loc) · 4.96 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
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');
%Train dataset
n=100;
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);
% Region of 8x8
xp0=[1:1/8:SubsetSize/8+1-1/8]+2;
yp0=[1:1/8:SubsetSize/8+1-1/8]+2;
xxp0=1:(SubsetSize/8)+3;
yyp0=1:(SubsetSize/8)+3;
[Xp_subset0,Yp_subset0] = meshgrid(xp0,yp0);
for l = 1:n
% A random displamcent for each region 8x8
f = randi([-100 100],SubsetSize/8+3,SubsetSize/8+3)/100;
g = randi([-100 100],SubsetSize/8+3,SubsetSize/8+3)/100;
% linear interpolation between the randoom displacments
x0 = Xp_subset0 ;
y0 = Yp_subset0 ;
disp_x = interp2(xxp0,yyp0,f,x0,y0,'linear');
disp_y = interp2(xxp0,yyp0,g,x0,y0,'linear');
% 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_%03d.csv',img,l);
name_def = sprintf('Train_Data/Def%03d_%03d.csv',img,l);
name_dispx = sprintf('Train_Data/Dispx%03d_%03d.csv',img,l);
name_dispy = sprintf('Train_Data/Dispy%03d_%03d.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', '%.2f');
dlmwrite(name_dispy, disp_y, 'delimiter', ',', 'precision', '%.2f');
end
end
%Test dataset
n=1;
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);
% Region of 8x8
xp0=[1:1/8:SubsetSize/8+1-1/8]+2;
yp0=[1:1/8:SubsetSize/8+1-1/8]+2;
xxp0=1:(SubsetSize/8)+3;
yyp0=1:(SubsetSize/8)+3;
[Xp_subset0,Yp_subset0] = meshgrid(xp0,yp0);
for l = 1:n
% A random displamcent for each region 8x8
f = randi([-100 100],SubsetSize/8+3,SubsetSize/8+3)/100;
g = randi([-100 100],SubsetSize/8+3,SubsetSize/8+3)/100;
% linear interpolation between the randoom displacments
x0 = Xp_subset0 ;
y0 = Yp_subset0 ;
disp_x = interp2(xxp0,yyp0,f,x0,y0,'linear');
disp_y = interp2(xxp0,yyp0,g,x0,y0,'linear');
% 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_%03d.csv',img,l);
name_def = sprintf('Test_Data/Def%03d_%03d.csv',img,l);
name_dispx = sprintf('Test_Data/Dispx%03d_%03d.csv',img,l);
name_dispy = sprintf('Test_Data/Dispy%03d_%03d.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', '%.2f');
dlmwrite(name_dispy, disp_y, 'delimiter', ',', 'precision', '%.2f');
end
end