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