-
Notifications
You must be signed in to change notification settings - Fork 1
/
MotionAnalysisCoordinatesRegions.m
88 lines (68 loc) · 2.91 KB
/
MotionAnalysisCoordinatesRegions.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
%% CODE WRITTEN BY ... [TO BE ADDED IF PAPER IS ACCEPTED] AND USED IN PLOS ONE PAPER "SYNCHRONIZATION AND DECEPTION"
%% WHAT THIS PROGRAM DOES:
% 1. Takes as input all videos to be analyzed
% 2. Allows user to interactively mark mid screen and regions of interest for extracting motion energy flows ...
% ... saves coordinates in data array structure to be used in MotionAnalysisGenerateFlow.m ...
clear Points
close
CWD = '~vids/'; % folder with videos
tally = 0;
allfiles = dir('~vids/'); % folder with videos
%%
for k = 1:length(allfiles)
af1 = struct2cell(allfiles(k));
holdtemp = cell2mat(af1(1));
disp(holdtemp)
if (strcmp(holdtemp,'.') ~= 1) && (strcmp(holdtemp,'..') ~= 1) && (strcmp(holdtemp,'.DS_Store') ~= 1),
tally = tally + 1;
movLoc = strcat(CWD,holdtemp);
LeftCount = 0;
RightCount = 0;
BothCount = 0;
%%// get video information
vidobj=VideoReader(movLoc);
numFrames = get(vidobj,'NumberOfFrames');
vidHeight = vidobj.Height;
vidWidth = vidobj.Width;
vidFrameRate = vidobj.FrameRate;
%%
for m = 100, %%// select arbitrary point somwehere in video
mov1(1) = struct('cdata',zeros(vidHeight, vidWidth, 3, 'uint8'),'colormap',[]);
mov1(1).cdata = read(vidobj,m);
fig = figure(1);
image(mov1(1).cdata);
dcm_obj = datacursormode(fig);
set(dcm_obj,'DisplayStyle','datatip',...
'SnapToDataVertex','off','Enable','on')
%%// interactive selection of x,y points on screen corresponding to regions of interest
disp('Click MIDSCREEN X, then press ENTER ')
pause
midX = getCursorInfo(dcm_obj);
midvalueX = midX.Position(1)
disp('Click LEFT LEGS Y, then press ENTER ')
pause
lapLY = getCursorInfo(dcm_obj);
legsYLEFT = lapLY.Position(2)
disp('Click LEFT HEAD Y, then press ENTER ')
pause
headLY = getCursorInfo(dcm_obj);
headYLEFT = headLY.Position(2)
disp('Click RIGHT LEGS Y, then press ENTER ')
pause
lapRY = getCursorInfo(dcm_obj);
legsYRIGHT = lapRY.Position(2)
disp('Click RIGHT HEAD Y, then press ENTER ')
pause
headRY = getCursorInfo(dcm_obj);
headYRIGHT = headRY.Position(2)
%%// for each dyad, save x.y coordinates for regions of interest in the data structure "Points"
dyadnum = strsplit(holdtemp,'_');
ordernum = strsplit(cell2mat(dyadnum(2)),'.');
Points.coord(tally,:) = [str2num(cell2mat(dyadnum(1))), str2num(cell2mat(ordernum(1))), midvalueX , legsYLEFT, headYLEFT, legsYRIGHT, headYRIGHT];
close
end
clear mov1(1).cdata
close
end
end
save('~/pointsmarkedRegions','Points')