Showing
5 changed files
with
0 additions
and
863 deletions
hyuna_allfile/augment.m
deleted
100644 → 0
1 | -clear; | ||
2 | - | ||
3 | -path_name = '/home/hyuna/Documents/actionGAN_work/7/7_right_skeleton/'; | ||
4 | -fileID = fopen('/home/hyuna/Documents/actionGAN_work/7/7_good_right.txt','r'); | ||
5 | -formatSpec = '%s'; | ||
6 | -sizeA = [20 Inf]; | ||
7 | -perfect_list = fscanf(fileID,formatSpec,sizeA); | ||
8 | -perfect_list = perfect_list.'; | ||
9 | -fclose(fileID); | ||
10 | - | ||
11 | -L = length(perfect_list); | ||
12 | - | ||
13 | -for K = 1:L | ||
14 | - file_name = char(perfect_list(K,:)); | ||
15 | - name = strcat(path_name,file_name(1:20),'.skeleton'); | ||
16 | - disp(name); | ||
17 | - [token,remainder] = strtok(file_name,'A'); | ||
18 | - | ||
19 | - class = str2num(remainder(2:4)); | ||
20 | - %class=remainder(2:4); | ||
21 | - | ||
22 | - if class == 7 | ||
23 | - bodyinfo = read_skeleton_file(name); | ||
24 | - frame_num = size(bodyinfo,2); | ||
25 | - | ||
26 | - | ||
27 | - try | ||
28 | - %initialize | ||
29 | - cur_subject_x = zeros(frame_num, 25); | ||
30 | - cur_subject_y = zeros(frame_num, 25); | ||
31 | - cur_subject_z = zeros(frame_num, 25); | ||
32 | - | ||
33 | - tot_x = zeros(frame_num,25); | ||
34 | - tot_y = zeros(frame_num,25); | ||
35 | - tot_z = zeros(frame_num,25); | ||
36 | - | ||
37 | - joint_5 = zeros(1,3); | ||
38 | - joint_9 = zeros(1,3); | ||
39 | - joint_1 = zeros(1,3); | ||
40 | - joint_3 = zeros(1,3); | ||
41 | - | ||
42 | - %get total joints information | ||
43 | - for FN = 1:frame_num | ||
44 | - cur_body = bodyinfo(FN).bodies(1); | ||
45 | - joints = cur_body.joints; | ||
46 | - | ||
47 | - for JN = 1:25 | ||
48 | - tot_x(FN,JN) = joints(JN).x; | ||
49 | - tot_y(FN,JN) = joints(JN).y; | ||
50 | - tot_z(FN,JN) = joints(JN).z; | ||
51 | - end | ||
52 | - end | ||
53 | - | ||
54 | - %Orientation normalization 1 : in space | ||
55 | - %get median values | ||
56 | - M_x = median(tot_x); | ||
57 | - M_y = median(tot_y); | ||
58 | - M_z = median(tot_z); | ||
59 | - | ||
60 | - %set 3 points for make plane | ||
61 | - joint_5 = [M_x(5) M_y(5) M_z(5)]; | ||
62 | - joint_9 = [M_x(9) M_y(9) M_z(9)]; | ||
63 | - joint_1 = [M_x(1) M_y(1) M_z(1)]; | ||
64 | - joint_3 = [M_x(3) M_y(3) M_z(3)]; | ||
65 | - | ||
66 | - %find RIGID TRNASFORMATION matrix | ||
67 | - d1 = joint_1 - joint_5; | ||
68 | - d2 = joint_1 - joint_9; | ||
69 | - n1 = cross(d1,d2); % because we will parallel transform, don't need to find belly | ||
70 | - u1 = n1/norm(n1); | ||
71 | - u2 = [0 0 1]; | ||
72 | - cs1 = dot(u1,u2)/norm(u1)*norm(u2); | ||
73 | - ss1 = sqrt(1-cs1.^2); | ||
74 | - v1 = cross(u1,u2)/norm(cross(u1,u2)); | ||
75 | - | ||
76 | - R1 = [v1(1)*v1(1)*(1-cs1)+cs1 v1(1)*v1(2)*(1-cs1)-v1(3)*ss1 v1(1)*v1(3)*(1-cs1)+v1(2)*ss1]; | ||
77 | - R1(2,:) = [v1(1)*v1(2)*(1-cs1)+v1(3)*ss1 v1(2)*v1(2)*(1-cs1)+cs1 v1(2)*v1(3)*(1-cs1)-v1(1)*ss1]; | ||
78 | - R1(3,:) = [v1(1)*v1(3)*(1-cs1)-v1(2)*ss1 v1(2)*v1(3)*(1-cs1)+v1(1)*ss1 v1(3)*v1(3)*(1-cs1)+cs1]; | ||
79 | - | ||
80 | - %1-3 number tolls to parallel x axis. Rigid transformation on plane surface | ||
81 | - %Z axis coords oyler angle transform | ||
82 | - | ||
83 | - t = joint_3 - joint_1; | ||
84 | - d3 = R1(1,:) * t.'; | ||
85 | - d3(1,2) = R1(2,:) * t.'; | ||
86 | - d3(1,3) = R1(3,:) * t.'; | ||
87 | - | ||
88 | - u3 = d3(1:2)/norm(d3(1:2)); | ||
89 | - v3 = [u3(1) -u3(2)]; | ||
90 | - v3(2,:) = [u3(2) u3(1)]; | ||
91 | - u4 = [1 0].'; | ||
92 | - | ||
93 | - csss = v3\u4; | ||
94 | - cs2 = csss(1); | ||
95 | - ss2 = csss(2); | ||
96 | - | ||
97 | - R2 = [cs2 -ss2 0]; | ||
98 | - R2(2,:) = [ss2 cs2 0]; | ||
99 | - R2(3,:) = [0 0 1]; | ||
100 | - | ||
101 | - | ||
102 | - %apply rigid transformation | ||
103 | - for FN = 1:frame_num | ||
104 | - cur_body = bodyinfo(FN).bodies(1); | ||
105 | - joints = cur_body.joints; | ||
106 | - | ||
107 | - for JN = 1:25 | ||
108 | - a = R1(1,:) * [joints(JN).x joints(JN).y joints(JN).z].'; | ||
109 | - b = R1(2,:) * [joints(JN).x joints(JN).y joints(JN).z].'; | ||
110 | - c = R1(3,:) * [joints(JN).x joints(JN).y joints(JN).z].'; | ||
111 | - | ||
112 | - cur_subject_x(FN,JN) = R2(1,:) * [a b c].'; | ||
113 | - cur_subject_y(FN,JN) = R2(2,:) * [a b c].'; | ||
114 | - cur_subject_z(FN,JN) = R2(3,:) * [a b c].'; | ||
115 | - | ||
116 | - end | ||
117 | - end | ||
118 | - | ||
119 | - %orientation normalize 2 in plane surface | ||
120 | - if cur_subject_x(1,4) < cur_subject_x(1,1) | ||
121 | - cur_subject_x = 0 - cur_subject_x; | ||
122 | - end | ||
123 | - | ||
124 | - if cur_subject_y(1,9) > cur_subject_y(1,5) | ||
125 | - cur_subject_y = 0 - cur_subject_y; | ||
126 | - end | ||
127 | - | ||
128 | - % for save origin subjects before data augment | ||
129 | - clear_subject_x = cur_subject_x; | ||
130 | - clear_subject_y = cur_subject_y; | ||
131 | - clear_subject_z = cur_subject_z; | ||
132 | - | ||
133 | - % Left <-> Right Change : 2option | ||
134 | - for LR = 1:2 | ||
135 | - if LR == 1 | ||
136 | - augment_y = clear_subject_y; | ||
137 | - else | ||
138 | - augment_y = 0 - clear_subject_y; | ||
139 | - end | ||
140 | - | ||
141 | - %Height change : 3option | ||
142 | - for HE = 1:3 | ||
143 | - if HE == 1 | ||
144 | - augment_x = clear_subject_x.* 1.2; | ||
145 | - elseif HE==2 | ||
146 | - augment_x = clear_subject_x.* 1.0; | ||
147 | - else | ||
148 | - augment_x = clear_subject_x.* 0.8; | ||
149 | - end | ||
150 | - | ||
151 | - %Give Gaussian Random Variable : 0.01 - 6times | ||
152 | - for RV = 1:75 | ||
153 | - %3. Gaussian Random filter 0.1 | ||
154 | - cur_subject_x = augment_x + 0.01.*randn(frame_num,25); | ||
155 | - cur_subject_y = augment_y + 0.01.*randn(frame_num,25); | ||
156 | - cur_subject_z = clear_subject_z + 0.01.*randn(frame_num,25); | ||
157 | - | ||
158 | - % NORMALIZATION | ||
159 | - cur_subject_x = cur_subject_x - min(cur_subject_x(:)); | ||
160 | - max_tall = max(cur_subject_x(:)); | ||
161 | - cur_subject_x = cur_subject_x ./ max_tall; | ||
162 | - | ||
163 | - cur_subject_y = cur_subject_y - min(cur_subject_y(:)); | ||
164 | - cur_subject_y = cur_subject_y ./ max_tall; | ||
165 | - | ||
166 | - cur_subject_z = cur_subject_z - min(cur_subject_z(:)); | ||
167 | - cur_subject_z = cur_subject_z ./ max_tall; | ||
168 | - | ||
169 | - | ||
170 | - %Write image | ||
171 | - motionpatch = cur_subject_x; | ||
172 | - motionpatch(:,:,2) = cur_subject_y; | ||
173 | - motionpatch(:,:,3) = cur_subject_z; | ||
174 | - | ||
175 | - new_file_name = strcat('/home/hyuna/Documents/actionGAN_work/7/7_augment_right/',file_name(1:20),'_',num2str(LR),num2str(HE),num2str(RV),'.png'); | ||
176 | - imwrite(motionpatch,new_file_name); | ||
177 | - | ||
178 | - end | ||
179 | - end | ||
180 | - end | ||
181 | - | ||
182 | - catch | ||
183 | - name | ||
184 | - end | ||
185 | - end | ||
186 | -end | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
hyuna_allfile/cleaning.m
deleted
100644 → 0
1 | - | ||
2 | -% 맨처음 방향 (frame1) 으로 일괄 orientation normalize | ||
3 | -% => 1번프레임이 아니라 프레임들의 중앙값 | ||
4 | -% 키로 모든방향 normalize | ||
5 | -% 노멀라이즈시 최소값 빼는게 아니라 joint1-> 0.5/0.5/0.5로 가도록 | ||
6 | -% 실험할때 전방향 노멀라이즈도 해봐야겠다.. | ||
7 | -path_name ='/home/hyuna/Documents/actionGAN_work/24/24_all_skeleton/'; | ||
8 | -dinfo=dir('/home/hyuna/Documents/actionGAN_work/24/24_all_skeleton/S007C002P016R002A024.skeleton'); | ||
9 | -%txt=fullfile(dir_to_search, '*.skeleton'); | ||
10 | -%dinfo=dir(txt); | ||
11 | -count=[0,0,0]; | ||
12 | - | ||
13 | -for d = 1: length(dinfo) | ||
14 | - label=-1; | ||
15 | - file_name = dinfo(d).name; | ||
16 | - % disp(name); | ||
17 | - | ||
18 | - name = strcat(path_name,file_name(1:20),'.skeleton'); | ||
19 | - [token,remainder] = strtok(file_name,'A'); | ||
20 | - | ||
21 | - class = str2num(remainder(2:4)); | ||
22 | - %class=remainder(2:4); | ||
23 | - | ||
24 | - if class == 24 | ||
25 | - bodyinfo = read_skeleton_file(name); | ||
26 | - frame_num = size(bodyinfo,2); | ||
27 | - | ||
28 | - else | ||
29 | - continue; | ||
30 | - end | ||
31 | - | ||
32 | - if isempty(bodyinfo) || isempty(bodyinfo(1).bodies()) | ||
33 | - disp("empty body"); | ||
34 | - newdir='/home/hyuna/Documents/actionGAN_work/24/24_emptybody.txt'; | ||
35 | - | ||
36 | - txtfile=fopen(newdir,'a'); | ||
37 | - fprintf(txtfile, file_name(1:20)); | ||
38 | - fprintf(txtfile, '\n'); | ||
39 | - fclose(txtfile); | ||
40 | - count(1)=count(1)+1; | ||
41 | - continue; | ||
42 | - end | ||
43 | - | ||
44 | - | ||
45 | - %initialize | ||
46 | - cur_subject_x = zeros(frame_num, 25); | ||
47 | - cur_subject_y = zeros(frame_num, 25); | ||
48 | - cur_subject_z = zeros(frame_num, 25); | ||
49 | - | ||
50 | - tot_x = zeros(frame_num,25); | ||
51 | - tot_y = zeros(frame_num,25); | ||
52 | - tot_z = zeros(frame_num,25); | ||
53 | - | ||
54 | - joint_5 = zeros(1,3); | ||
55 | - joint_9 = zeros(1,3); | ||
56 | - joint_1 = zeros(1,3); | ||
57 | - joint_3 = zeros(1,3); | ||
58 | - | ||
59 | - | ||
60 | - | ||
61 | - %get total joints information | ||
62 | - for FN = 1:frame_num | ||
63 | - | ||
64 | - cur_body = bodyinfo(FN).bodies(1); | ||
65 | - joints = cur_body.joints; | ||
66 | - | ||
67 | - for JN = 1:25 | ||
68 | - tot_x(FN,JN) = joints(JN).x; | ||
69 | - tot_y(FN,JN) = joints(JN).y; | ||
70 | - tot_z(FN,JN) = joints(JN).z; | ||
71 | - end | ||
72 | - end | ||
73 | - | ||
74 | - %Orientation normalization 1 : in space | ||
75 | - %get median values | ||
76 | - M_x = median(tot_x); | ||
77 | - M_y = median(tot_y); | ||
78 | - M_z = median(tot_z); | ||
79 | - | ||
80 | - %set 3 points for make plane | ||
81 | - joint_5 = [M_x(5) M_y(5) M_z(5)]; | ||
82 | - joint_9 = [M_x(9) M_y(9) M_z(9)]; | ||
83 | - joint_1 = [M_x(1) M_y(1) M_z(1)]; | ||
84 | - joint_3 = [M_x(3) M_y(3) M_z(3)]; | ||
85 | - | ||
86 | - %find RIGID TRNASFORMATION matrix | ||
87 | - d1 = joint_1 - joint_5; | ||
88 | - d2 = joint_1 - joint_9; | ||
89 | - n1 = cross(d1,d2); % because we will parallel transform, don't need to find belly | ||
90 | - u1 = n1/norm(n1); | ||
91 | - u2 = [0 0 1]; | ||
92 | - cs1 = dot(u1,u2)/norm(u1)*norm(u2); | ||
93 | - ss1 = sqrt(1-cs1.^2); | ||
94 | - v1 = cross(u1,u2)/norm(cross(u1,u2)); | ||
95 | - | ||
96 | - R1 = [v1(1)*v1(1)*(1-cs1)+cs1 v1(1)*v1(2)*(1-cs1)-v1(3)*ss1 v1(1)*v1(3)*(1-cs1)+v1(2)*ss1]; | ||
97 | - R1(2,:) = [v1(1)*v1(2)*(1-cs1)+v1(3)*ss1 v1(2)*v1(2)*(1-cs1)+cs1 v1(2)*v1(3)*(1-cs1)-v1(1)*ss1]; | ||
98 | - R1(3,:) = [v1(1)*v1(3)*(1-cs1)-v1(2)*ss1 v1(2)*v1(3)*(1-cs1)+v1(1)*ss1 v1(3)*v1(3)*(1-cs1)+cs1]; | ||
99 | - | ||
100 | - %1-3 number tolls to parallel x axis. Rigid transformation on plane surface | ||
101 | - %Z axis coords oyler angle transform | ||
102 | - | ||
103 | - t = joint_3 - joint_1; | ||
104 | - d3 = R1(1,:) * t.'; | ||
105 | - d3(1,2) = R1(2,:) * t.'; | ||
106 | - d3(1,3) = R1(3,:) * t.'; | ||
107 | - | ||
108 | - u3 = d3(1:2)/norm(d3(1:2)); | ||
109 | - v3 = [u3(1) -u3(2)]; | ||
110 | - v3(2,:) = [u3(2) u3(1)]; | ||
111 | - u4 = [1 0].'; | ||
112 | - | ||
113 | - csss = v3\u4; | ||
114 | - cs2 = csss(1); | ||
115 | - ss2 = csss(2); | ||
116 | - | ||
117 | - R2 = [cs2 -ss2 0]; | ||
118 | - R2(2,:) = [ss2 cs2 0]; | ||
119 | - R2(3,:) = [0 0 1]; | ||
120 | - | ||
121 | - | ||
122 | - %apply rigid transformation | ||
123 | - for FN = 1:frame_num | ||
124 | - cur_body = bodyinfo(FN).bodies(1); | ||
125 | - joints = cur_body.joints; | ||
126 | - | ||
127 | - for JN = 1:25 | ||
128 | - a = R1(1,:) * [joints(JN).x joints(JN).y joints(JN).z].'; | ||
129 | - b = R1(2,:) * [joints(JN).x joints(JN).y joints(JN).z].'; | ||
130 | - c = R1(3,:) * [joints(JN).x joints(JN).y joints(JN).z].'; | ||
131 | - | ||
132 | - cur_subject_x(FN,JN) = R2(1,:) * [a b c].'; | ||
133 | - cur_subject_y(FN,JN) = R2(2,:) * [a b c].'; | ||
134 | - cur_subject_z(FN,JN) = R2(3,:) * [a b c].'; | ||
135 | - | ||
136 | - end | ||
137 | - end | ||
138 | - | ||
139 | - %orientation normalize 2 (with plane surface) | ||
140 | - if cur_subject_x(1,4) < cur_subject_x(1,1) | ||
141 | - cur_subject_x = 0 - cur_subject_x; | ||
142 | - end | ||
143 | - | ||
144 | - if cur_subject_y(1,9) > cur_subject_y(1,5) | ||
145 | - cur_subject_y = 0 - cur_subject_y; | ||
146 | - end | ||
147 | - | ||
148 | - % for save origin subjects before data augment | ||
149 | - clear_subject_x = cur_subject_x; | ||
150 | - clear_subject_y = cur_subject_y; | ||
151 | - clear_subject_z = cur_subject_z; | ||
152 | - | ||
153 | - % patch_num*25 | ||
154 | - red=[4,3,21,2,1]; | ||
155 | - green=[5,6,7,8,23,22]; | ||
156 | - blue=[9,10,11,12,25,24]; | ||
157 | - yellow=[17,18,19,20]; | ||
158 | - skyblue=[13,14,15,16]; | ||
159 | - | ||
160 | - target = {skyblue,yellow,green,blue}; | ||
161 | - [r,c]=size(target); | ||
162 | - | ||
163 | - %celldisp(target); | ||
164 | - %disp(c); | ||
165 | - %disp(target{1}); | ||
166 | - | ||
167 | - % joint-to-joint | ||
168 | - for tar_index = 1:c | ||
169 | - diff_ave = comp_aver(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,target{tar_index}); | ||
170 | - | ||
171 | - if label~=0 | ||
172 | - label=set_label(diff_ave,0.13); | ||
173 | - end | ||
174 | - | ||
175 | - if label==0 %bad | ||
176 | - disp(file_name(1:20)); | ||
177 | - disp("difference"); | ||
178 | - disp(tar_index); | ||
179 | - %disp(target(tar_index)); | ||
180 | - disp(diff_ave); | ||
181 | - end | ||
182 | - end | ||
183 | - | ||
184 | - | ||
185 | - % reds(head-spine) shoud be parallel to z | ||
186 | - % 4 3 21 2 1 | ||
187 | - | ||
188 | - max_t=[]; | ||
189 | - | ||
190 | - for j = 1: length(red)-1 | ||
191 | - theta_per_patch=[]; | ||
192 | - for patch = 1:frame_num | ||
193 | - u = [clear_subject_x(patch, red(j+1))-clear_subject_x(patch, red(j)),clear_subject_y(patch, red(j+1))-clear_subject_y(patch, red(j)),clear_subject_z(patch, red(j+1))-clear_subject_z(patch, red(j))]; | ||
194 | - % v = axis z | ||
195 | - v = [0,0,1]; | ||
196 | - % angle between [vector joint to joint] and [axis z] | ||
197 | - theta = atan2(norm(cross(u,v)),dot(u,v)); | ||
198 | - %if theta > 90 | ||
199 | - %theta = theta - 90; | ||
200 | - %end | ||
201 | - | ||
202 | - %print all the theta and max of it. | ||
203 | - %disp(theta); | ||
204 | - | ||
205 | - theta_per_patch=[theta_per_patch, theta]; | ||
206 | - end | ||
207 | - % maximum theta for each bones through all the patches | ||
208 | - % max_t[4] | ||
209 | - max_t = [max_t,max(theta_per_patch)]; | ||
210 | - clear theta_per_patch; | ||
211 | - | ||
212 | - end | ||
213 | - %disp("max"); | ||
214 | - %disp(max_t); | ||
215 | - % usually 1.6<max angle<=1.8 | ||
216 | - if label~=0 | ||
217 | - label=set_label(max_t,1.8); | ||
218 | - end | ||
219 | - % green, blue(arms) should be located in almost the same position at the | ||
220 | - % beginning and end of motion. | ||
221 | - | ||
222 | - | ||
223 | - %print a distance between starting and ending coords | ||
224 | - g_distance=loc_end_to_end(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,skyblue); | ||
225 | - b_distance=loc_end_to_end(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,yellow); | ||
226 | - | ||
227 | - | ||
228 | - % only use just 2 joints at the tip of arms(hands) | ||
229 | - g_end=g_distance(end-1:end); | ||
230 | - b_end=b_distance(end-1:end); | ||
231 | - | ||
232 | - if label~=0 | ||
233 | - label=set_label(g_end,0.7); | ||
234 | - end | ||
235 | - | ||
236 | - % check if label is still 'good' | ||
237 | - if label~=0 | ||
238 | - label=set_label(b_end,0.7); | ||
239 | - end | ||
240 | - | ||
241 | - | ||
242 | - % save good and bad examples seperately | ||
243 | - newdir=''; | ||
244 | - if label==0 % bad | ||
245 | - newdir='/home/hyuna/Documents/actionGAN_work/24/24_bad.txt'; | ||
246 | - count(2)=count(2)+1; | ||
247 | - else | ||
248 | - newdir='/home/hyuna/Documents/actionGAN_work/24/24_good.txt'; | ||
249 | - count(3)=count(3)+1; | ||
250 | - copyfile(name,'/home/hyuna/Documents/actionGAN_work/24/24_good_skeleton'); | ||
251 | - | ||
252 | - major =major_limb(clear_subject_z, skyblue, yellow); | ||
253 | - if(major==skyblue) | ||
254 | - s_dir='/home/hyuna/Documents/actionGAN_work/24/good_right.txt'; | ||
255 | - copyfile(name,'/home/hyuna/Documents/actionGAN_work/24/24_right_skeleton'); | ||
256 | - else | ||
257 | - s_dir='/home/hyuna/Documents/actionGAN_work/24/good_left.txt'; | ||
258 | - copyfile(name,'/home/hyuna/Documents/actionGAN_work/24/24_left_skeleton'); | ||
259 | - end | ||
260 | - | ||
261 | - | ||
262 | - split=fopen(s_dir,'a'); | ||
263 | - fprintf(split, file_name(1:20)); | ||
264 | - fprintf(split, '\n'); | ||
265 | - fclose(split); | ||
266 | - | ||
267 | - end | ||
268 | - | ||
269 | - txtfile=fopen(newdir,'a'); | ||
270 | - fprintf(txtfile, file_name(1:20)); | ||
271 | - fprintf(txtfile, '\n'); | ||
272 | - fclose(txtfile); | ||
273 | - | ||
274 | - | ||
275 | -end | ||
276 | - | ||
277 | -% number of [emptybody, bad, good] | ||
278 | -disp(count); | ||
279 | - | ||
280 | -function setlabel=set_label(target,value) | ||
281 | -if target(target>value) %bad | ||
282 | - label=0; | ||
283 | - else | ||
284 | - label=1; | ||
285 | -end | ||
286 | -setlabel=label; | ||
287 | -end | ||
288 | - | ||
289 | - | ||
290 | -function loc_end=loc_end_to_end(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,target) | ||
291 | -distance = [] | ||
292 | - for j = 1: length(target) | ||
293 | - x_=clear_subject_x(1, target(j))-clear_subject_x(frame_num, target(j)); | ||
294 | - y_=clear_subject_y(1, target(j))-clear_subject_y(frame_num, target(j)); | ||
295 | - z_=clear_subject_z(1, target(j))-clear_subject_z(frame_num, target(j)); | ||
296 | - d=sqrt(x_*x_+y_*y_+z_*z_); | ||
297 | - distance=[distance,d]; | ||
298 | - end | ||
299 | -loc_end =distance; | ||
300 | -% disp(distance); | ||
301 | -end | ||
302 | - | ||
303 | -function comp_ave =comp_aver(clear_subject_x,clear_subject_y,clear_subject_z, frame_num,target) | ||
304 | -for j = 1: length(target) | ||
305 | - % distance between a particular joint and average coordinate per patch | ||
306 | - dist_ave=[]; | ||
307 | - for patch = 2:frame_num-1 | ||
308 | - ave_x=(clear_subject_x(patch-1,target(j))+clear_subject_x(patch+1,target(j)))/2; | ||
309 | - ave_y=(clear_subject_y(patch-1,target(j))+clear_subject_y(patch+1,target(j)))/2; | ||
310 | - ave_z=(clear_subject_z(patch-1,target(j))+clear_subject_z(patch+1,target(j)))/2; | ||
311 | - | ||
312 | - % distance between joint and average | ||
313 | - jnt_ave = sqrt((abs(clear_subject_x(patch, target(j))-ave_x)).^2+ (abs(clear_subject_y(patch, target(j))-ave_y)).^2+ (abs(clear_subject_z(patch, target(j))-ave_z)).^2); | ||
314 | - dist_ave=[dist_ave,jnt_ave]; | ||
315 | - | ||
316 | - end | ||
317 | - | ||
318 | -end | ||
319 | - comp_ave=dist_ave; | ||
320 | -end | ||
321 | -function limb= major_limb(clear_subject_z, target1, target2) | ||
322 | - z1=max(clear_subject_z(:,target1(end))) - clear_subject_z(1, target1(end)); | ||
323 | - z2=max(clear_subject_z(:,target2(end))) - clear_subject_z(1, target2(end)); | ||
324 | - | ||
325 | - if z1>z2 % target1 raised higher than t2 | ||
326 | - limb=target1; | ||
327 | - else | ||
328 | - limb=target2; | ||
329 | - end | ||
330 | - | ||
331 | -end | ||
332 | - |
hyuna_allfile/transform_all_hyuna.m
deleted
100644 → 0
1 | -clear; | ||
2 | - | ||
3 | -path_name = '/media/hyuna/F4722E97722E5F1C/21.nturgb+d_skeletons/'; | ||
4 | -fileID = fopen('/media/hyuna/F4722E97722E5F1C/sk.txt','r'); | ||
5 | -formatSpec = '%s'; | ||
6 | -sizeA = [20 Inf]; | ||
7 | -perfect_list = fscanf(fileID,formatSpec,sizeA); | ||
8 | -perfect_list = perfect_list.'; | ||
9 | -fclose(fileID); | ||
10 | - | ||
11 | -L = length(perfect_list); | ||
12 | - | ||
13 | -for K = 1:L | ||
14 | - | ||
15 | - file_name = char(perfect_list(K,:)); | ||
16 | - name = strcat(path_name,file_name(1:20),'.skeleton'); | ||
17 | - disp(name); | ||
18 | - [token,remainder] = strtok(file_name,'A'); | ||
19 | - | ||
20 | - class = str2num(remainder(2:4)); | ||
21 | - %class=remainder(2:4); | ||
22 | - | ||
23 | - if class == 7 | ||
24 | - bodyinfo = read_skeleton_file(name); | ||
25 | - frame_num = size(bodyinfo,2); | ||
26 | - | ||
27 | - | ||
28 | - try | ||
29 | - %initialize | ||
30 | - cur_subject_x = zeros(frame_num, 25); | ||
31 | - cur_subject_y = zeros(frame_num, 25); | ||
32 | - cur_subject_z = zeros(frame_num, 25); | ||
33 | - | ||
34 | - tot_x = zeros(frame_num,25); | ||
35 | - tot_y = zeros(frame_num,25); | ||
36 | - tot_z = zeros(frame_num,25); | ||
37 | - | ||
38 | - joint_5 = zeros(1,3); | ||
39 | - joint_9 = zeros(1,3); | ||
40 | - joint_1 = zeros(1,3); | ||
41 | - joint_3 = zeros(1,3); | ||
42 | - | ||
43 | - %get total joints information | ||
44 | - for FN = 1:frame_num | ||
45 | - cur_body = bodyinfo(FN).bodies(1); | ||
46 | - joints = cur_body.joints; | ||
47 | - | ||
48 | - for JN = 1:25 | ||
49 | - tot_x(FN,JN) = joints(JN).x; | ||
50 | - tot_y(FN,JN) = joints(JN).y; | ||
51 | - tot_z(FN,JN) = joints(JN).z; | ||
52 | - end | ||
53 | - end | ||
54 | - | ||
55 | - %Orientation normalization 1 : in space | ||
56 | - %get median values | ||
57 | - M_x = median(tot_x); | ||
58 | - M_y = median(tot_y); | ||
59 | - M_z = median(tot_z); | ||
60 | - | ||
61 | - %set 3 points for make plane | ||
62 | - joint_5 = [M_x(5) M_y(5) M_z(5)]; | ||
63 | - joint_9 = [M_x(9) M_y(9) M_z(9)]; | ||
64 | - joint_1 = [M_x(1) M_y(1) M_z(1)]; | ||
65 | - joint_3 = [M_x(3) M_y(3) M_z(3)]; | ||
66 | - | ||
67 | - %find RIGID TRNASFORMATION matrix | ||
68 | - d1 = joint_1 - joint_5; | ||
69 | - d2 = joint_1 - joint_9; | ||
70 | - n1 = cross(d1,d2); % because we will parallel transform, don't need to find belly | ||
71 | - u1 = n1/norm(n1); | ||
72 | - u2 = [0 0 1]; | ||
73 | - cs1 = dot(u1,u2)/norm(u1)*norm(u2); | ||
74 | - ss1 = sqrt(1-cs1.^2); | ||
75 | - v1 = cross(u1,u2)/norm(cross(u1,u2)); | ||
76 | - | ||
77 | - R1 = [v1(1)*v1(1)*(1-cs1)+cs1 v1(1)*v1(2)*(1-cs1)-v1(3)*ss1 v1(1)*v1(3)*(1-cs1)+v1(2)*ss1]; | ||
78 | - R1(2,:) = [v1(1)*v1(2)*(1-cs1)+v1(3)*ss1 v1(2)*v1(2)*(1-cs1)+cs1 v1(2)*v1(3)*(1-cs1)-v1(1)*ss1]; | ||
79 | - R1(3,:) = [v1(1)*v1(3)*(1-cs1)-v1(2)*ss1 v1(2)*v1(3)*(1-cs1)+v1(1)*ss1 v1(3)*v1(3)*(1-cs1)+cs1]; | ||
80 | - | ||
81 | - %1-3 number tolls to parallel x axis. Rigid transformation on plane surface | ||
82 | - %Z axis coords oyler angle transform | ||
83 | - | ||
84 | - t = joint_3 - joint_1; | ||
85 | - d3 = R1(1,:) * t.'; | ||
86 | - d3(1,2) = R1(2,:) * t.'; | ||
87 | - d3(1,3) = R1(3,:) * t.'; | ||
88 | - | ||
89 | - u3 = d3(1:2)/norm(d3(1:2)); | ||
90 | - v3 = [u3(1) -u3(2)]; | ||
91 | - v3(2,:) = [u3(2) u3(1)]; | ||
92 | - u4 = [1 0].'; | ||
93 | - | ||
94 | - csss = v3\u4; | ||
95 | - cs2 = csss(1); | ||
96 | - ss2 = csss(2); | ||
97 | - | ||
98 | - R2 = [cs2 -ss2 0]; | ||
99 | - R2(2,:) = [ss2 cs2 0]; | ||
100 | - R2(3,:) = [0 0 1]; | ||
101 | - | ||
102 | - | ||
103 | - %apply rigid transformation | ||
104 | - for FN = 1:frame_num | ||
105 | - cur_body = bodyinfo(FN).bodies(1); | ||
106 | - joints = cur_body.joints; | ||
107 | - | ||
108 | - for JN = 1:25 | ||
109 | - a = R1(1,:) * [joints(JN).x joints(JN).y joints(JN).z].'; | ||
110 | - b = R1(2,:) * [joints(JN).x joints(JN).y joints(JN).z].'; | ||
111 | - c = R1(3,:) * [joints(JN).x joints(JN).y joints(JN).z].'; | ||
112 | - | ||
113 | - cur_subject_x(FN,JN) = R2(1,:) * [a b c].'; | ||
114 | - cur_subject_y(FN,JN) = R2(2,:) * [a b c].'; | ||
115 | - cur_subject_z(FN,JN) = R2(3,:) * [a b c].'; | ||
116 | - | ||
117 | - end | ||
118 | - end | ||
119 | - | ||
120 | - %orientation normalize 2 in plane surface | ||
121 | - if cur_subject_x(1,4) < cur_subject_x(1,1) | ||
122 | - cur_subject_x = 0 - cur_subject_x; | ||
123 | - end | ||
124 | - | ||
125 | - if cur_subject_y(1,9) > cur_subject_y(1,5) | ||
126 | - cur_subject_y = 0 - cur_subject_y; | ||
127 | - end | ||
128 | - | ||
129 | - % for save origin subjects before data augment | ||
130 | - clear_subject_x = cur_subject_x; | ||
131 | - clear_subject_y = cur_subject_y; | ||
132 | - clear_subject_z = cur_subject_z; | ||
133 | - | ||
134 | - % Left <-> Right Change : 2option | ||
135 | - for LR = 1:2 | ||
136 | - if LR == 1 | ||
137 | - augment_y = clear_subject_y; | ||
138 | - else | ||
139 | - augment_y = 0 - clear_subject_y; | ||
140 | - end | ||
141 | - | ||
142 | - %Height change : 3option | ||
143 | - for HE = 1:3 | ||
144 | - if HE == 1 | ||
145 | - augment_x = clear_subject_x.* 1.2; | ||
146 | - elseif HE==2 | ||
147 | - augment_x = clear_subject_x.* 1.0; | ||
148 | - else | ||
149 | - augment_x = clear_subject_x.* 0.8; | ||
150 | - end | ||
151 | - | ||
152 | - %Give Gaussian Random Variable : 0.01 - 6times | ||
153 | - for RV = 1:6 | ||
154 | - %3. Gaussian Random filter 0.1 | ||
155 | - cur_subject_x = augment_x + 0.01.*randn(frame_num,25); | ||
156 | - cur_subject_y = augment_y + 0.01.*randn(frame_num,25); | ||
157 | - cur_subject_z = clear_subject_z + 0.01.*randn(frame_num,25); | ||
158 | - | ||
159 | - % NORMALIZATION | ||
160 | - cur_subject_x = cur_subject_x - min(cur_subject_x(:)); | ||
161 | - max_tall = max(cur_subject_x(:)); | ||
162 | - cur_subject_x = cur_subject_x ./ max_tall; | ||
163 | - | ||
164 | - cur_subject_y = cur_subject_y - min(cur_subject_y(:)); | ||
165 | - cur_subject_y = cur_subject_y ./ max_tall; | ||
166 | - | ||
167 | - cur_subject_z = cur_subject_z - min(cur_subject_z(:)); | ||
168 | - cur_subject_z = cur_subject_z ./ max_tall; | ||
169 | - | ||
170 | - | ||
171 | - %Write image | ||
172 | - motionpatch = cur_subject_x; | ||
173 | - motionpatch(:,:,2) = cur_subject_y; | ||
174 | - motionpatch(:,:,3) = cur_subject_z; | ||
175 | - | ||
176 | - new_file_name = strcat('/home/hyuna/Documents/actionGAN_work/24/24_kicking',file_name(1:20),'_',num2str(LR),num2str(HE),num2str(RV),'.png'); | ||
177 | - imwrite(motionpatch,new_file_name); | ||
178 | - | ||
179 | - end | ||
180 | - end | ||
181 | - end | ||
182 | - | ||
183 | - catch | ||
184 | - name | ||
185 | - end | ||
186 | - end | ||
187 | -end |
hyuna_allfile/transform_all_orig
deleted
100644 → 0
File mode changed
hyuna_allfile/transform_all_orig.m
deleted
100644 → 0
1 | -clear; | ||
2 | - | ||
3 | -path_name = '/media/hyuna/F4722E97722E5F1C/21.nturgb+d_skeletons/'; | ||
4 | -fileID = fopen('/media/hyuna/F4722E97722E5F1C/sk.txt','r'); | ||
5 | -formatSpec = '%s'; | ||
6 | -sizeA = [20 Inf]; | ||
7 | -perfect_list = fscanf(fileID,formatSpec,sizeA); | ||
8 | -perfect_list = perfect_list.'; | ||
9 | -fclose(fileID); | ||
10 | - | ||
11 | -L = length(perfect_list); | ||
12 | - | ||
13 | -for K = 1:L | ||
14 | - | ||
15 | - file_name = char(perfect_list(K,:)); | ||
16 | - name = strcat(path_name,file_name(1:20),'.skeleton'); | ||
17 | - | ||
18 | - [token,remainder] = strtok(file_name,'A'); | ||
19 | - | ||
20 | - class = str2num(remainder(2:4)); | ||
21 | - %class=remainder(2:4); | ||
22 | - | ||
23 | - if class == 7 | ||
24 | - disp(name); | ||
25 | - bodyinfo = read_skeleton_file(name); | ||
26 | - frame_num = size(bodyinfo,2); | ||
27 | - | ||
28 | - try | ||
29 | - %initialize | ||
30 | - cur_subject_x = zeros(frame_num, 25); | ||
31 | - cur_subject_y = zeros(frame_num, 25); | ||
32 | - cur_subject_z = zeros(frame_num, 25); | ||
33 | - | ||
34 | - tot_x = zeros(frame_num,25); | ||
35 | - tot_y = zeros(frame_num,25); | ||
36 | - tot_z = zeros(frame_num,25); | ||
37 | - | ||
38 | - joint_5 = zeros(1,3); | ||
39 | - joint_9 = zeros(1,3); | ||
40 | - joint_1 = zeros(1,3); | ||
41 | - joint_3 = zeros(1,3); | ||
42 | - | ||
43 | - %get total joints information | ||
44 | - for FN = 1:frame_num | ||
45 | - cur_body = bodyinfo(FN).bodies(1); | ||
46 | - joints = cur_body.joints; | ||
47 | - | ||
48 | - for JN = 1:25 | ||
49 | - tot_x(FN,JN) = joints(JN).x; | ||
50 | - tot_y(FN,JN) = joints(JN).y; | ||
51 | - tot_z(FN,JN) = joints(JN).z; | ||
52 | - end | ||
53 | - end | ||
54 | - | ||
55 | - %Orientation normalization 1 : in space | ||
56 | - %get median values | ||
57 | - M_x = median(tot_x); | ||
58 | - M_y = median(tot_y); | ||
59 | - M_z = median(tot_z); | ||
60 | - | ||
61 | - %set 3 points for make plane | ||
62 | - joint_5 = [M_x(5) M_y(5) M_z(5)]; | ||
63 | - joint_9 = [M_x(9) M_y(9) M_z(9)]; | ||
64 | - joint_1 = [M_x(1) M_y(1) M_z(1)]; | ||
65 | - joint_3 = [M_x(3) M_y(3) M_z(3)]; | ||
66 | - | ||
67 | - %find RIGID TRNASFORMATION matrix | ||
68 | - d1 = joint_1 - joint_5; | ||
69 | - d2 = joint_1 - joint_9; | ||
70 | - n1 = cross(d1,d2); % because we will parallel transform, don't need to find belly | ||
71 | - u1 = n1/norm(n1); | ||
72 | - u2 = [0 0 1]; | ||
73 | - cs1 = dot(u1,u2)/norm(u1)*norm(u2); | ||
74 | - ss1 = sqrt(1-cs1.^2); | ||
75 | - v1 = cross(u1,u2)/norm(cross(u1,u2)); | ||
76 | - | ||
77 | - R1 = [v1(1)*v1(1)*(1-cs1)+cs1 v1(1)*v1(2)*(1-cs1)-v1(3)*ss1 v1(1)*v1(3)*(1-cs1)+v1(2)*ss1]; | ||
78 | - R1(2,:) = [v1(1)*v1(2)*(1-cs1)+v1(3)*ss1 v1(2)*v1(2)*(1-cs1)+cs1 v1(2)*v1(3)*(1-cs1)-v1(1)*ss1]; | ||
79 | - R1(3,:) = [v1(1)*v1(3)*(1-cs1)-v1(2)*ss1 v1(2)*v1(3)*(1-cs1)+v1(1)*ss1 v1(3)*v1(3)*(1-cs1)+cs1]; | ||
80 | - | ||
81 | - %1-3 number tolls to parallel x axis. Rigid transformation on plane surface | ||
82 | - %Z axis coords oyler angle transform | ||
83 | - | ||
84 | - t = joint_3 - joint_1; | ||
85 | - d3 = R1(1,:) * t.'; | ||
86 | - d3(1,2) = R1(2,:) * t.'; | ||
87 | - d3(1,3) = R1(3,:) * t.'; | ||
88 | - | ||
89 | - u3 = d3(1:2)/norm(d3(1:2)); | ||
90 | - v3 = [u3(1) -u3(2)]; | ||
91 | - v3(2,:) = [u3(2) u3(1)]; | ||
92 | - u4 = [1 0].'; | ||
93 | - | ||
94 | - csss = v3\u4; | ||
95 | - cs2 = csss(1); | ||
96 | - ss2 = csss(2); | ||
97 | - | ||
98 | - R2 = [cs2 -ss2 0]; | ||
99 | - R2(2,:) = [ss2 cs2 0]; | ||
100 | - R2(3,:) = [0 0 1]; | ||
101 | - | ||
102 | - | ||
103 | - %apply rigid transformation | ||
104 | - for FN = 1:frame_num | ||
105 | - cur_body = bodyinfo(FN).bodies(1); | ||
106 | - joints = cur_body.joints; | ||
107 | - | ||
108 | - for JN = 1:25 | ||
109 | - a = R1(1,:) * [joints(JN).x joints(JN).y joints(JN).z].'; | ||
110 | - b = R1(2,:) * [joints(JN).x joints(JN).y joints(JN).z].'; | ||
111 | - c = R1(3,:) * [joints(JN).x joints(JN).y joints(JN).z].'; | ||
112 | - | ||
113 | - cur_subject_x(FN,JN) = R2(1,:) * [a b c].'; | ||
114 | - cur_subject_y(FN,JN) = R2(2,:) * [a b c].'; | ||
115 | - cur_subject_z(FN,JN) = R2(3,:) * [a b c].'; | ||
116 | - | ||
117 | - end | ||
118 | - end | ||
119 | - | ||
120 | - %orientation normalize 2 in plane surface | ||
121 | - if cur_subject_x(1,4) < cur_subject_x(1,1) | ||
122 | - cur_subject_x = 0 - cur_subject_x; | ||
123 | - end | ||
124 | - | ||
125 | - if cur_subject_y(1,9) > cur_subject_y(1,5) | ||
126 | - cur_subject_y = 0 - cur_subject_y; | ||
127 | - end | ||
128 | - | ||
129 | - % for save origin subjects before data augment | ||
130 | - clear_subject_x = cur_subject_x; | ||
131 | - clear_subject_y = cur_subject_y; | ||
132 | - clear_subject_z = cur_subject_z; | ||
133 | - | ||
134 | - % NORMALIZATION | ||
135 | - cur_subject_x = cur_subject_x - min(cur_subject_x(:)); | ||
136 | - max_tall = max(cur_subject_x(:))*2; | ||
137 | - cur_subject_x = cur_subject_x ./ max_tall; | ||
138 | - | ||
139 | - cur_subject_y = cur_subject_y - min(cur_subject_y(:)); | ||
140 | - cur_subject_y = cur_subject_y ./ max_tall; | ||
141 | - | ||
142 | - cur_subject_z = cur_subject_z - min(cur_subject_z(:)); | ||
143 | - cur_subject_z = cur_subject_z ./ max_tall; | ||
144 | - | ||
145 | - %Write image | ||
146 | - motionpatch = cur_subject_x; | ||
147 | - motionpatch(:,:,2) = cur_subject_y; | ||
148 | - motionpatch(:,:,3) = cur_subject_z; | ||
149 | - | ||
150 | - new_file_name = strcat('/home/hyuna/Documents/actionGAN_work/',file_name(1:20),'.png'); | ||
151 | - imwrite(motionpatch,new_file_name); | ||
152 | - %copyfile(name,'/home/hyuna/Documents/actionGAN_work/24/24_all_skeleton'); | ||
153 | - | ||
154 | - catch | ||
155 | - name | ||
156 | - end | ||
157 | - end | ||
158 | -end |
-
Please register or login to post a comment