annotate toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/HHMM/Square/get_square_data.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 % Let the user draw a square with the mouse,
Daniel@0 2 % and then click on the corners to do a manual segmentation
Daniel@0 3
Daniel@0 4 ss = 6;
Daniel@0 5 Q1 = 1; Q2 = 2; Q3 = 3; obsvel = 6;
Daniel@0 6 CLOCKWISE = 1; ANTICLOCK = 2;
Daniel@0 7 LR = 1; UD = 2; RL = 3; DU = 4;
Daniel@0 8
Daniel@0 9 % repeat this block manually incrementing the sequence number
Daniel@0 10 % and setting ori.
Daniel@0 11 % (since I don't know how to call getmouse as a call-return function).
Daniel@0 12 seq = 4;
Daniel@0 13 %ori = CLOCKWISE
Daniel@0 14 ori = ANTICLOCK;
Daniel@0 15 clear xpos ypos
Daniel@0 16 getmouse
Daniel@0 17 % end block
Daniel@0 18
Daniel@0 19 % manual segmentation with the mouse
Daniel@0 20 startseg(1) = 1;
Daniel@0 21 for i=2:4
Daniel@0 22 fprintf('click on start of segment %d\n', i);
Daniel@0 23 [x,y] = ginput(1);
Daniel@0 24 plot(x,y,'ro')
Daniel@0 25 d = dist2([xpos; ypos]', [x y]);
Daniel@0 26 startseg(i) = argmin(d);
Daniel@0 27 end
Daniel@0 28
Daniel@0 29 % plot corners in green
Daniel@0 30 %ti = first point in (i+1)st segment
Daniel@0 31 t1 = startseg(1); t2 = startseg(2); t3 = startseg(3); t4 = startseg(4);
Daniel@0 32 plot(xpos(t2), ypos(t2), 'g*')
Daniel@0 33 plot(xpos(t3), ypos(t3), 'g*')
Daniel@0 34 plot(xpos(t4), ypos(t4), 'g*')
Daniel@0 35
Daniel@0 36
Daniel@0 37 xvel = xpos(2:end) - xpos(1:end-1);
Daniel@0 38 yvel = ypos(2:end) - ypos(1:end-1);
Daniel@0 39 speed = [xvel(:)'; yvel(:)'];
Daniel@0 40 pos_data{seq} = [xpos(:)'; ypos(:)'];
Daniel@0 41 vel_data{seq} = [xvel(:)'; yvel(:)'];
Daniel@0 42 T = length(xvel);
Daniel@0 43 Q1label{seq} = num2cell(repmat(ori, 1, T));
Daniel@0 44 Q2label{seq} = zeros(1, T);
Daniel@0 45 if ori == CLOCKWISE
Daniel@0 46 Q2label{seq}(t1:t2) = LR;
Daniel@0 47 Q2label{seq}(t2+1:t3) = UD;
Daniel@0 48 Q2label{seq}(t3+1:t4) = RL;
Daniel@0 49 Q2label{seq}(t4+1:T) = DU;
Daniel@0 50 else
Daniel@0 51 Q2label{seq}(t1:t2) = RL;
Daniel@0 52 Q2label{seq}(t2+1:t3) = UD;
Daniel@0 53 Q2label{seq}(t3+1:t4) = LR;
Daniel@0 54 Q2label{seq}(t4+1:T) = DU;
Daniel@0 55 end
Daniel@0 56
Daniel@0 57 % pos_data{seq}(:,t), vel_data{seq}(:,t) Q1label{seq}(t) Q2label{seq}(t)
Daniel@0 58 save 'square4' pos_data vel_data Q1label Q2label
Daniel@0 59
Daniel@0 60 nseq = 4;
Daniel@0 61 cases = cell(1,nseq);
Daniel@0 62 for seq=1:nseq
Daniel@0 63 T = size(vel_data{seq},2);
Daniel@0 64 ev = cell(ss,T);
Daniel@0 65 ev(obsvel,:) = num2cell(vel_data{seq},1);
Daniel@0 66 ev(Q1,:) = Q1label{seq};
Daniel@0 67 ev(Q2,:) = num2cell(Q2label{seq});
Daniel@0 68 cases{seq} = ev;
Daniel@0 69 end
Daniel@0 70 save 'square4_cases' cases