조현아

filter by motionpatch

1 +
2 +
3 +path_name ='C:\\Users\\User\\Documents\\gan_work\\25\\';
4 +dinfo=dir('C:\\Users\\User\\Documents\\gan_work\\25\\*.png');
5 +%txt=fullfile(dir_to_search, '*.png');
6 +%dinfo=dir(txt);
7 +
8 +
9 +
10 +%disp(cur_subject_x);
11 +
12 +
13 +count=[0,0,0];
14 +for d = 1: length(dinfo)
15 +
16 + label=-1;
17 + file_name = dinfo(d).name;
18 +
19 + motionpatch=imread(fullfile(path_name, file_name));
20 + cur_subject_x=double(motionpatch(:,:,1))./255;
21 + cur_subject_y=double(motionpatch(:,:,2))./255;
22 + cur_subject_z=double(motionpatch(:,:,3))./255;
23 +
24 + frame_num = size(cur_subject_x,1);
25 +
26 + name = strcat(path_name,file_name(1:length(file_name)),'.png');
27 +
28 + % for save origin subjects before data augment
29 + clear_subject_x = cur_subject_x;
30 + clear_subject_y = cur_subject_y;
31 + clear_subject_z = cur_subject_z;
32 +
33 + % patch_num*25
34 + red=[4,3,21,2,1];
35 + green=[5,6,7,8,23,22];
36 + blue=[9,10,11,12,25,24];
37 + yellow=[17,18,19,20];
38 + skyblue=[13,14,15,16];
39 +
40 +
41 +
42 + target = {skyblue,yellow,green,blue};
43 + [r,c]=size(target);
44 +
45 + %celldisp(target);
46 + %disp(c);
47 + %disp(target{1});
48 +
49 + % joint-to-joint
50 + for tar_index = 1:c
51 + diff_ave = comp_aver(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,target{tar_index});
52 +
53 + if label~=0
54 + label=set_label(diff_ave,0.13);
55 + end
56 +
57 + %{
58 + if label==0 %bad
59 + disp(file_name(1:20));
60 + disp("difference");
61 + disp(tar_index);
62 + disp(target(tar_index));
63 + disp(diff_ave);
64 + end
65 + %}
66 +
67 + end
68 +
69 +
70 + % reds(head-spine) shoud be always parallel to z
71 + if label~=0
72 + label=set_label(stand_straight(clear_subject_x,clear_subject_y,clear_subject_z, 1,frame_num,red),1.8);
73 + end
74 +
75 + % should check straightness for both legs in case 27 only for start and
76 + % end of execution
77 + %{
78 + if label~=0
79 + disp(name);
80 + disp(stand_straight(clear_subject_x,clear_subject_y,clear_subject_z, 1,3, skyblue));
81 + disp(stand_straight(clear_subject_x,clear_subject_y,clear_subject_z, frame_num-3,frame_num, skyblue));
82 + end
83 + %}
84 +
85 + for tar_index = 1:c
86 + label= set_label(stand_straight(clear_subject_x,clear_subject_y,clear_subject_z, 1,3, target{tar_index}),2.0);
87 + if label==0
88 + break;
89 + end
90 +
91 + label= set_label(stand_straight(clear_subject_x,clear_subject_y,clear_subject_z, frame_num-3,frame_num, target{tar_index}),2.0);
92 + if label==0
93 + break;
94 + end
95 + end
96 +
97 +
98 +
99 + % save good and bad examples seperately
100 + newdir='';
101 + if label==0 % bad
102 + newdir='C:\\Users\\User\\Documents\\gan_work\\datas\\mp_bad_1.1.txt';
103 + count(2)=count(2)+1;
104 + %copyfile(name,'C:\\Users\\User\\Documents\\gan_work\\datas\\mp_bad');
105 + else % good
106 + newdir='C:\\Users\\User\\Documents\\gan_work\\datas\\mp_good_1.1.txt';
107 + count(3)=count(3)+1;
108 + %copyfile(name,'C:\\Users\\User\\Documents\\gan_work\\datas\\mp_good');
109 +
110 + % The condition below is used for a class with subclasses of right/left major limb.
111 + %{
112 + major =major_limb(clear_subject_z, skyblue, yellow);
113 + if(major==skyblue)
114 + s_dir='/home/hyuna/Documents/actionGAN_work/24/24_good_right.txt';
115 + copyfile(name,'/home/hyuna/Documents/actionGAN_work/24/24_right_skeleton');
116 + else
117 + s_dir='/home/hyuna/Documents/actionGAN_work/24/24_good_left.txt';
118 + copyfile(name,'/home/hyuna/Documents/actionGAN_work/24/24_left_skeleton');
119 + end
120 + %}
121 +
122 + % The condition below is used for a class 27 to classify how many
123 + % times it jumped.
124 +
125 +
126 + end
127 +
128 + txtfile=fopen(newdir,'a');
129 + fprintf(txtfile,file_name(1:length(file_name)));
130 + fprintf(txtfile, '\n');
131 + fclose(txtfile);
132 +
133 +end
134 +
135 +% number of [emptybody, bad, good]
136 +disp(count);
137 +
138 +
139 +
140 +function stand=stand_straight(clear_subject_x,clear_subject_y,clear_subject_z, start,end_ind,target)
141 +max_t=[];
142 +
143 +for j = 1: length(target)-1
144 + theta_per_patch=[];
145 + for patch = start:end_ind % usually 1:frame_num
146 + u = [clear_subject_x(patch, target(j+1))-clear_subject_x(patch, target(j)),clear_subject_y(patch, target(j+1))-clear_subject_y(patch, target(j)),clear_subject_z(patch, target(j+1))-clear_subject_z(patch, target(j))];
147 + % v = axis z
148 + v = [0,0,1];
149 + % angle between [vector joint to joint] and [axis z]
150 + theta = atan2(norm(cross(u,v)),dot(u,v));
151 + %if theta > 90
152 + %theta = theta - 90;
153 + %end
154 +
155 + %print all the theta and max of it.
156 + %disp(theta);
157 +
158 + theta_per_patch=[theta_per_patch, theta];
159 + end
160 + % maximum theta for each bones through all the patches
161 + % max_t[4]
162 + max_t = [max_t,max(theta_per_patch)];
163 + clear theta_per_patch;
164 +
165 +end
166 +%disp("max");
167 +%disp(max_t);
168 +% usually 1.6<max angle<=1.8
169 +stand=max_t;
170 +end
171 +
172 +
173 +function setlabel=set_label(target,value)
174 +value=value*1.1;
175 +if target(target>value) %bad
176 + label=0;
177 +else
178 + label=1;
179 +end
180 +setlabel=label;
181 +end
182 +
183 +
184 +function loc_end=loc_end_to_end(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,target)
185 +echo off;
186 +distance=[];
187 +
188 +for j = 1: length(target)
189 + x_=clear_subject_x(1, target(j))-clear_subject_x(frame_num, target(j));
190 + y_=clear_subject_y(1, target(j))-clear_subject_y(frame_num, target(j));
191 + z_=clear_subject_z(1, target(j))-clear_subject_z(frame_num, target(j));
192 + d=sqrt(x_*x_+y_*y_+z_*z_);
193 + distance=[distance,d];
194 + end
195 +loc_end =distance;
196 +% disp(distance);
197 +end
198 +
199 +function comp_ave =comp_aver(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,target)
200 +for j = 1: length(target)
201 + % distance between a particular joint and average coordinate per patch
202 + dist_ave=[];
203 +
204 +
205 + for patch = 2:frame_num-1
206 + % disp(patch);
207 + ave_x=(clear_subject_x(patch-1,target(j))+clear_subject_x(patch+1,target(j)))/2;
208 + ave_y=(clear_subject_y(patch-1,target(j))+clear_subject_y(patch+1,target(j)))/2;
209 + ave_z=(clear_subject_z(patch-1,target(j))+clear_subject_z(patch+1,target(j)))/2;
210 +
211 + % distance between joint and average
212 + 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);
213 + dist_ave=[dist_ave,jnt_ave];
214 +
215 + end
216 +
217 +end
218 + comp_ave=dist_ave;
219 +end
220 +function limb= major_limb(clear_subject_z, target1, target2)
221 + z1=max(clear_subject_z(:,target1(end))) - clear_subject_z(1, target1(end));
222 + z2=max(clear_subject_z(:,target2(end))) - clear_subject_z(1, target2(end));
223 +
224 + if z1>z2 % target1 raised higher than t2
225 + limb=target1;
226 + else
227 + limb=target2;
228 + end
229 +
230 +end
231 +
232 +function num = num_jumped(clear_subject_z, target,frame_num)
233 + state=0; %
234 + for i = 1: frame_num-1
235 + % check if it had descended
236 + if state==1 && clear_subject_z(i,target) < clear_subject_z(i+1,target)
237 + state=2;
238 +
239 + elseif clear_subject_z(i,target)>clear_subject_z(i+1,target)
240 + state=1; % first descending
241 + else
242 + state=-1;
243 + end
244 + end
245 + num=state;
246 +end
247 +
248 +
249 +
1 +path_name ='C:\\Users\\User\\Documents\\gan_work\\25\\';
2 +dinfo=dir('C:\\Users\\User\\Documents\\gan_work\\25\\*.png');
3 +count=[0,0,0];
4 +
5 +for d = 1: length(dinfo)
6 + label=-1;
7 + file_name = dinfo(d).name;
8 +
9 + motionpatch=imread(fullfile(path_name, file_name));
10 + cur_subject_x=double(motionpatch(:,:,1))./255;
11 + cur_subject_y=double(motionpatch(:,:,2))./255;
12 + cur_subject_z=double(motionpatch(:,:,3))./255;
13 +
14 + frame_num = size(cur_subject_x,1);
15 +
16 + name = strcat(path_name,file_name(1:length(file_name)),'.png');
17 +
18 + % for save origin subjects before data augment
19 + clear_subject_x = cur_subject_x;
20 + clear_subject_y = cur_subject_y;
21 + clear_subject_z = cur_subject_z;
22 +
23 + % patch_num*25
24 + red=[4,3,21,2,1];
25 + green=[5,6,7,8,23,22];
26 + blue=[9,10,11,12,25,24];
27 + skyblue=[17,18,19,20];
28 + yellow=[13,14,15,16];
29 +
30 + target = {skyblue,yellow,green,blue};
31 + [r,c]=size(target);
32 +
33 + %celldisp(target);
34 + %disp(c);
35 + %disp(target{1});
36 +
37 + % joint-to-joint
38 + for tar_index = 1:c
39 + diff_ave = comp_aver(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,target{tar_index});
40 +
41 + if label~=0
42 + label=set_label(diff_ave,0.13);
43 + end
44 +
45 + if label==0 %bad
46 + disp(file_name(1:20));
47 + disp("difference");
48 + disp(target(tar_index));
49 + disp(diff_ave);
50 + end
51 + end
52 +
53 +
54 + % reds(head-spine) shoud be parallel to z
55 + % 4 3 21 2 1
56 +
57 + max_t=[];
58 +
59 + for j = 1: length(red)-1
60 + theta_per_patch=[];
61 + for patch = 1:frame_num
62 + 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))];
63 + % v = axis z
64 + v = [0,0,1];
65 + % angle between [vector joint to joint] and [axis z]
66 + theta = atan2(norm(cross(u,v)),dot(u,v));
67 + %if theta > 90
68 + %theta = theta - 90;
69 + %end
70 +
71 + %print all the theta and max of it.
72 + %disp(theta);
73 +
74 + theta_per_patch=[theta_per_patch, theta];
75 + end
76 + % maximum theta for each bones through all the patches
77 + % max_t[4]
78 + max_t = [max_t,max(theta_per_patch)];
79 + clear theta_per_patch;
80 +
81 + end
82 + %disp("max");
83 + %disp(max_t);
84 + % usually 1.6<max angle<=1.8
85 + if label~=0
86 + label=set_label(max_t,1.8);
87 + end
88 + % green, blue(arms) should be located in almost the same position at the
89 + % beginning and end of motion.
90 +
91 +
92 + %print a distance between starting and ending coords
93 + g_distance=loc_end_to_end(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,yellow);
94 + b_distance=loc_end_to_end(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,skyblue);
95 +
96 +
97 + % only use just 2 joints at the tip of arms(hands)
98 + g_end=g_distance(end-1:end);
99 + b_end=b_distance(end-1:end);
100 +
101 + if label~=0
102 + label=set_label(g_end,0.7);
103 + end
104 +
105 + % check if label is still 'good'
106 + if label~=0
107 + label=set_label(b_end,0.7);
108 + end
109 +
110 +
111 + % save good and bad examples seperately
112 + newdir='';
113 + if label==0 % bad
114 + newdir='/home/hyuna/Documents/actionGAN_work/7_bad.txt';
115 + count(2)=count(2)+1;
116 + else
117 + newdir='/home/hyuna/Documents/actionGAN_work/7_good.txt';
118 + count(3)=count(3)+1;
119 + %copyfile(name,'/home/hyuna/Documents/actionGAN_work/7_good_skeleton');
120 +
121 + major =arms(clear_subject_z, yellow, skyblue);
122 + if(major==yellow)
123 + s_dir='/home/hyuna/Documents/actionGAN_work/good_right.txt';
124 + copyfile(name,'/home/hyuna/Documents/actionGAN_work/right_skeleton');
125 + else
126 + s_dir='/home/hyuna/Documents/actionGAN_work/good_left.txt';
127 + copyfile(name,'/home/hyuna/Documents/actionGAN_work/left_skeleton');
128 + end
129 +
130 +
131 + split=fopen(s_dir,'a');
132 + fprintf(split, file_name(1:20));
133 + fprintf(split, '\n');
134 + fclose(split);
135 +
136 + end
137 +
138 + txtfile=fopen(newdir,'a');
139 + fprintf(txtfile, file_name(1:20));
140 + fprintf(txtfile, '\n');
141 + fclose(txtfile);
142 +
143 +
144 +end
145 +
146 +% number of [emptybody, bad, good]
147 +disp(count);
148 +
149 +function setlabel=set_label(target,value)
150 +value=value*1.1;
151 +if target(target>value) %bad
152 + label=0;
153 + else
154 + label=1;
155 +end
156 +setlabel=label;
157 +end
158 +
159 +
160 +function loc_end=loc_end_to_end(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,target)
161 +distance = []
162 + for j = 1: length(target)
163 + x_=clear_subject_x(1, target(j))-clear_subject_x(frame_num, target(j));
164 + y_=clear_subject_y(1, target(j))-clear_subject_y(frame_num, target(j));
165 + z_=clear_subject_z(1, target(j))-clear_subject_z(frame_num, target(j));
166 + d=sqrt(x_*x_+y_*y_+z_*z_);
167 + distance=[distance,d];
168 + end
169 +loc_end =distance;
170 +% disp(distance);
171 +end
172 +
173 +function comp_ave =comp_aver(clear_subject_x,clear_subject_y,clear_subject_z, frame_num,target)
174 +for j = 1: length(target)
175 + % distance between a particular joint and average coordinate per patch
176 + dist_ave=[];
177 + for patch = 2:frame_num-1
178 + ave_x=(clear_subject_x(patch-1,target(j))+clear_subject_x(patch+1,target(j)))/2;
179 + ave_y=(clear_subject_y(patch-1,target(j))+clear_subject_y(patch+1,target(j)))/2;
180 + ave_z=(clear_subject_z(patch-1,target(j))+clear_subject_z(patch+1,target(j)))/2;
181 +
182 + % distance between joint and average
183 + 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);
184 + dist_ave=[dist_ave,jnt_ave];
185 +
186 + end
187 +
188 +end
189 + comp_ave=dist_ave;
190 +end
191 +function major_arm= arms(clear_subject_z, target1, target2)
192 + z1=max(clear_subject_z(:,target1(end))) - clear_subject_z(1, target1(end));
193 + z2=max(clear_subject_z(:,target2(end))) - clear_subject_z(1, target2(end));
194 +
195 + if z1>z2 % target1 raised higher than t2
196 + major_arm=target1;
197 + else
198 + major_arm=target2;
199 + end
200 +
201 +end
202 +
1 +
2 +
3 +path_name ='C:\\Users\\User\\Documents\\gan_work\\25\\';
4 +dinfo=dir('C:\\Users\\User\\Documents\\gan_work\\25\\*.png');
5 +%txt=fullfile(dir_to_search, '*.png');
6 +%dinfo=dir(txt);
7 +
8 +
9 +
10 +%disp(cur_subject_x);
11 +
12 +
13 +count=[0,0,0];
14 +for d = 1: length(dinfo)
15 +
16 + label=-1;
17 + file_name = dinfo(d).name;
18 +
19 + motionpatch=imread(fullfile(path_name, file_name));
20 + cur_subject_x=double(motionpatch(:,:,1))./255;
21 + cur_subject_y=double(motionpatch(:,:,2))./255;
22 + cur_subject_z=double(motionpatch(:,:,3))./255;
23 +
24 + frame_num = size(cur_subject_x,1);
25 +
26 + name = strcat(path_name,file_name(1:length(file_name)),'.png');
27 +
28 + % for save origin subjects before data augment
29 + clear_subject_x = cur_subject_x;
30 + clear_subject_y = cur_subject_y;
31 + clear_subject_z = cur_subject_z;
32 +
33 + % patch_num*25
34 + red=[4,3,21,2,1];
35 + green=[5,6,7,8,23,22];
36 + blue=[9,10,11,12,25,24];
37 + yellow=[17,18,19,20];
38 + skyblue=[13,14,15,16];
39 +
40 +
41 +
42 + target = {skyblue,yellow,green,blue};
43 + [r,c]=size(target);
44 +
45 + %celldisp(target);
46 + %disp(c);
47 + %disp(target{1});
48 +
49 + % joint-to-joint
50 + for tar_index = 1:c
51 + diff_ave = comp_aver(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,target{tar_index});
52 +
53 + if label~=0
54 + label=set_label(diff_ave,0.13);
55 + end
56 +
57 + %{
58 + if label==0 %bad
59 + disp(file_name(1:20));
60 + disp("difference");
61 + disp(tar_index);
62 + disp(target(tar_index));
63 + disp(diff_ave);
64 + end
65 + %}
66 +
67 + end
68 +
69 +
70 + % reds(head-spine) shoud be always parallel to z
71 + if label~=0
72 + label=set_label(stand_straight(clear_subject_x,clear_subject_y,clear_subject_z, 1,frame_num,red),1.8);
73 + end
74 +
75 + % should check straightness for both legs in case 27 only for start and
76 + % end of execution
77 + %{
78 + if label~=0
79 + disp(name);
80 + disp(stand_straight(clear_subject_x,clear_subject_y,clear_subject_z, 1,3, skyblue));
81 + disp(stand_straight(clear_subject_x,clear_subject_y,clear_subject_z, frame_num-3,frame_num, skyblue));
82 + end
83 + %}
84 +
85 + for tar_index = 1:c
86 + label= set_label(stand_straight(clear_subject_x,clear_subject_y,clear_subject_z, 1,3, target{tar_index}),2.0);
87 + if label==0
88 + break;
89 + end
90 +
91 + label= set_label(stand_straight(clear_subject_x,clear_subject_y,clear_subject_z, frame_num-3,frame_num, target{tar_index}),2.0);
92 + if label==0
93 + break;
94 + end
95 + end
96 +
97 + % green, blue(arms) should be located in almost the same position at the
98 + % beginning and end of motion.
99 +
100 + %print a distance between starting and ending coords
101 + g_distance=loc_end_to_end(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,skyblue);
102 + b_distance=loc_end_to_end(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,yellow);
103 +
104 +
105 + % only use just 2 joints at the tip of arms(hands)
106 + g_end=g_distance(end-1:end);
107 + b_end=b_distance(end-1:end);
108 +
109 + if label~=0
110 + label=set_label(g_end,0.7);
111 + end
112 +
113 + % check if label is still 'good'
114 + if label~=0
115 + label=set_label(b_end,0.7);
116 + end
117 +
118 + ju1=0;
119 + ju2=0;
120 + if label~=0
121 + legs={skyblue, yellow};
122 +
123 + % count how many times it jumped for each leg
124 + ju1=num_jumped(clear_subject_z,legs{1}(2),frame_num);
125 + ju2=num_jumped(clear_subject_z,legs{2}(2),frame_num);
126 +
127 + if ju1 ~= ju2
128 + label = 0;
129 + end
130 + end
131 +
132 + % save good and bad examples seperately
133 + newdir='';
134 + if label==0 % bad
135 + newdir='C:\\Users\\User\\Documents\\gan_work\\datas\\mp_bad.txt';
136 + count(2)=count(2)+1;
137 + %copyfile(name,'C:\\Users\\User\\Documents\\gan_work\\datas\\mp_bad');
138 + else % good
139 + newdir='C:\\Users\\User\\Documents\\gan_work\\datas\\mp_good.txt';
140 + count(3)=count(3)+1;
141 + %copyfile(name,'C:\\Users\\User\\Documents\\gan_work\\datas\\mp_good');
142 +
143 + % The condition below is used for a class with subclasses of right/left major limb.
144 + %{
145 + major =major_limb(clear_subject_z, skyblue, yellow);
146 + if(major==skyblue)
147 + s_dir='/home/hyuna/Documents/actionGAN_work/24/24_good_right.txt';
148 + copyfile(name,'/home/hyuna/Documents/actionGAN_work/24/24_right_skeleton');
149 + else
150 + s_dir='/home/hyuna/Documents/actionGAN_work/24/24_good_left.txt';
151 + copyfile(name,'/home/hyuna/Documents/actionGAN_work/24/24_left_skeleton');
152 + end
153 + %}
154 +
155 + % The condition below is used for a class 27 to classify how many
156 + % times it jumped.
157 +
158 +
159 + end
160 +
161 + txtfile=fopen(newdir,'a');
162 + fprintf(txtfile,file_name(1:length(file_name)));
163 + fprintf(txtfile, '\n');
164 + fclose(txtfile);
165 +
166 +end
167 +
168 +% number of [emptybody, bad, good]
169 +disp(count);
170 +
171 +
172 +
173 +function stand=stand_straight(clear_subject_x,clear_subject_y,clear_subject_z, start,end_ind,target)
174 +max_t=[];
175 +
176 +for j = 1: length(target)-1
177 + theta_per_patch=[];
178 + for patch = start:end_ind % usually 1:frame_num
179 + u = [clear_subject_x(patch, target(j+1))-clear_subject_x(patch, target(j)),clear_subject_y(patch, target(j+1))-clear_subject_y(patch, target(j)),clear_subject_z(patch, target(j+1))-clear_subject_z(patch, target(j))];
180 + % v = axis z
181 + v = [0,0,1];
182 + % angle between [vector joint to joint] and [axis z]
183 + theta = atan2(norm(cross(u,v)),dot(u,v));
184 + %if theta > 90
185 + %theta = theta - 90;
186 + %end
187 +
188 + %print all the theta and max of it.
189 + %disp(theta);
190 +
191 + theta_per_patch=[theta_per_patch, theta];
192 + end
193 + % maximum theta for each bones through all the patches
194 + % max_t[4]
195 + max_t = [max_t,max(theta_per_patch)];
196 + clear theta_per_patch;
197 +
198 +end
199 +%disp("max");
200 +%disp(max_t);
201 +% usually 1.6<max angle<=1.8
202 +stand=max_t;
203 +end
204 +
205 +
206 +function setlabel=set_label(target,value)
207 +value=value*1.1;
208 +if target(target>value) %bad
209 + label=0;
210 +else
211 + label=1;
212 +end
213 +setlabel=label;
214 +end
215 +
216 +
217 +function loc_end=loc_end_to_end(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,target)
218 +echo off;
219 +distance=[];
220 +
221 +for j = 1: length(target)
222 + x_=clear_subject_x(1, target(j))-clear_subject_x(frame_num, target(j));
223 + y_=clear_subject_y(1, target(j))-clear_subject_y(frame_num, target(j));
224 + z_=clear_subject_z(1, target(j))-clear_subject_z(frame_num, target(j));
225 + d=sqrt(x_*x_+y_*y_+z_*z_);
226 + distance=[distance,d];
227 + end
228 +loc_end =distance;
229 +% disp(distance);
230 +end
231 +
232 +function comp_ave =comp_aver(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,target)
233 +for j = 1: length(target)
234 + % distance between a particular joint and average coordinate per patch
235 + dist_ave=[];
236 +
237 +
238 + for patch = 2:frame_num-1
239 + % disp(patch);
240 + ave_x=(clear_subject_x(patch-1,target(j))+clear_subject_x(patch+1,target(j)))/2;
241 + ave_y=(clear_subject_y(patch-1,target(j))+clear_subject_y(patch+1,target(j)))/2;
242 + ave_z=(clear_subject_z(patch-1,target(j))+clear_subject_z(patch+1,target(j)))/2;
243 +
244 + % distance between joint and average
245 + 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);
246 + dist_ave=[dist_ave,jnt_ave];
247 +
248 + end
249 +
250 +end
251 + comp_ave=dist_ave;
252 +end
253 +function limb= major_limb(clear_subject_z, target1, target2)
254 + z1=max(clear_subject_z(:,target1(end))) - clear_subject_z(1, target1(end));
255 + z2=max(clear_subject_z(:,target2(end))) - clear_subject_z(1, target2(end));
256 +
257 + if z1>z2 % target1 raised higher than t2
258 + limb=target1;
259 + else
260 + limb=target2;
261 + end
262 +
263 +end
264 +
265 +function num = num_jumped(clear_subject_z, target,frame_num)
266 + state=0; %
267 + for i = 1: frame_num-1
268 + % check if it had descended
269 + if state==1 && clear_subject_z(i,target) < clear_subject_z(i+1,target)
270 + state=2;
271 +
272 + elseif clear_subject_z(i,target)>clear_subject_z(i+1,target)
273 + state=1; % first descending
274 + else
275 + state=-1;
276 + end
277 + end
278 + num=state;
279 +end
280 +
281 +
282 +
1 +path_name ='C:\\Users\\User\\Documents\\gan_work\\25\\';
2 +dinfo=dir('C:\\Users\\User\\Documents\\gan_work\\25\\*.png');
3 +count=[0,0,0];
4 +
5 +for d = 1: length(dinfo)
6 + label=-1;
7 + file_name = dinfo(d).name;
8 +
9 + motionpatch=imread(fullfile(path_name, file_name));
10 + cur_subject_x=double(motionpatch(:,:,1))./255;
11 + cur_subject_y=double(motionpatch(:,:,2))./255;
12 + cur_subject_z=double(motionpatch(:,:,3))./255;
13 +
14 + frame_num = size(cur_subject_x,1);
15 +
16 + name = strcat(path_name,file_name(1:length(file_name)),'.png');
17 +
18 + % for save origin subjects before data augment
19 + clear_subject_x = cur_subject_x;
20 + clear_subject_y = cur_subject_y;
21 + clear_subject_z = cur_subject_z;
22 +
23 + % patch_num*25
24 + red=[4,3,21,2,1];
25 + green=[5,6,7,8,23,22];
26 + blue=[9,10,11,12,25,24];
27 + skyblue=[17,18,19,20];
28 + yellow=[13,14,15,16];
29 +
30 + target = {skyblue,yellow,green,blue};
31 + [r,c]=size(target);
32 +
33 + %celldisp(target);
34 + %disp(c);
35 + %disp(target{1});
36 +
37 + % joint-to-joint
38 + for tar_index = 1:c
39 + diff_ave = comp_aver(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,target{tar_index});
40 +
41 + if label~=0
42 + label=set_label(diff_ave,0.13);
43 + end
44 +
45 + if label==0 %bad
46 + disp(file_name(1:20));
47 + disp("difference");
48 + disp(target(tar_index));
49 + disp(diff_ave);
50 + end
51 + end
52 +
53 +
54 + % reds(head-spine) shoud be parallel to z
55 + % 4 3 21 2 1
56 +
57 + max_t=[];
58 +
59 + for j = 1: length(red)-1
60 + theta_per_patch=[];
61 + for patch = 1:frame_num
62 + 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))];
63 + % v = axis z
64 + v = [0,0,1];
65 + % angle between [vector joint to joint] and [axis z]
66 + theta = atan2(norm(cross(u,v)),dot(u,v));
67 + %if theta > 90
68 + %theta = theta - 90;
69 + %end
70 +
71 + %print all the theta and max of it.
72 + %disp(theta);
73 +
74 + theta_per_patch=[theta_per_patch, theta];
75 + end
76 + % maximum theta for each bones through all the patches
77 + % max_t[4]
78 + max_t = [max_t,max(theta_per_patch)];
79 + clear theta_per_patch;
80 +
81 + end
82 + %disp("max");
83 + %disp(max_t);
84 + % usually 1.6<max angle<=1.8
85 + if label~=0
86 + label=set_label(max_t,1.8);
87 + end
88 + % green, blue(arms) should be located in almost the same position at the
89 + % beginning and end of motion.
90 +
91 +
92 + %print a distance between starting and ending coords
93 + g_distance=loc_end_to_end(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,green);
94 + b_distance=loc_end_to_end(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,blue);
95 +
96 +
97 + % only use just 2 joints at the tip of arms(hands)
98 + g_end=g_distance(end-1:end);
99 + b_end=b_distance(end-1:end);
100 +
101 + if label~=0
102 + label=set_label(g_end,0.7);
103 + end
104 +
105 + % check if label is still 'good'
106 + if label~=0
107 + label=set_label(b_end,0.7);
108 + end
109 +
110 +
111 + % save good and bad examples seperately
112 + newdir='';
113 + if label==0 % bad
114 + newdir='/home/hyuna/Documents/actionGAN_work/7_bad.txt';
115 + count(2)=count(2)+1;
116 + else
117 + newdir='/home/hyuna/Documents/actionGAN_work/7_good.txt';
118 + count(3)=count(3)+1;
119 + %copyfile(name,'/home/hyuna/Documents/actionGAN_work/7_good_skeleton');
120 +
121 + major =arms(clear_subject_z, green, blue);
122 + if(major==green)
123 + s_dir='/home/hyuna/Documents/actionGAN_work/good_right.txt';
124 + copyfile(name,'/home/hyuna/Documents/actionGAN_work/right_skeleton');
125 + else
126 + s_dir='/home/hyuna/Documents/actionGAN_work/good_left.txt';
127 + copyfile(name,'/home/hyuna/Documents/actionGAN_work/left_skeleton');
128 + end
129 +
130 +
131 + split=fopen(s_dir,'a');
132 + fprintf(split, file_name(1:20));
133 + fprintf(split, '\n');
134 + fclose(split);
135 +
136 + end
137 +
138 + txtfile=fopen(newdir,'a');
139 + fprintf(txtfile, file_name(1:20));
140 + fprintf(txtfile, '\n');
141 + fclose(txtfile);
142 +
143 +
144 +end
145 +
146 +% number of [emptybody, bad, good]
147 +disp(count);
148 +
149 +function setlabel=set_label(target,value)
150 +value=value*1.1;
151 +if target(target>value) %bad
152 + label=0;
153 + else
154 + label=1;
155 +end
156 +setlabel=label;
157 +end
158 +
159 +
160 +function loc_end=loc_end_to_end(clear_subject_x,clear_subject_y,clear_subject_z,frame_num,target)
161 +distance = []
162 + for j = 1: length(target)
163 + x_=clear_subject_x(1, target(j))-clear_subject_x(frame_num, target(j));
164 + y_=clear_subject_y(1, target(j))-clear_subject_y(frame_num, target(j));
165 + z_=clear_subject_z(1, target(j))-clear_subject_z(frame_num, target(j));
166 + d=sqrt(x_*x_+y_*y_+z_*z_);
167 + distance=[distance,d];
168 + end
169 +loc_end =distance;
170 +% disp(distance);
171 +end
172 +
173 +function comp_ave =comp_aver(clear_subject_x,clear_subject_y,clear_subject_z, frame_num,target)
174 +for j = 1: length(target)
175 + % distance between a particular joint and average coordinate per patch
176 + dist_ave=[];
177 + for patch = 2:frame_num-1
178 + ave_x=(clear_subject_x(patch-1,target(j))+clear_subject_x(patch+1,target(j)))/2;
179 + ave_y=(clear_subject_y(patch-1,target(j))+clear_subject_y(patch+1,target(j)))/2;
180 + ave_z=(clear_subject_z(patch-1,target(j))+clear_subject_z(patch+1,target(j)))/2;
181 +
182 + % distance between joint and average
183 + 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);
184 + dist_ave=[dist_ave,jnt_ave];
185 +
186 + end
187 +
188 +end
189 + comp_ave=dist_ave;
190 +end
191 +function major_arm= arms(clear_subject_z, target1, target2)
192 + z1=max(clear_subject_z(:,target1(end))) - clear_subject_z(1, target1(end));
193 + z2=max(clear_subject_z(:,target2(end))) - clear_subject_z(1, target2(end));
194 +
195 + if z1>z2 % target1 raised higher than t2
196 + major_arm=target1;
197 + else
198 + major_arm=target2;
199 + end
200 +
201 +end
202 +