function out=legTrackerScoreMovie(mov,scoreJK,scoreBD,scoreKNN,KNNdata,colors) %Generates a movie with recorded video of a fly on the ball, manual %behavior scores, the KNN classifier scores, and visualizations of the data %vectors used to generate the classification. Used to make Movie S1. %Modified to make Movie S2 by commenting out the portions for displaying %the manual scores %Usage: %out=legTrackerScoreMovie(mov,scoreJK,scoreBD,scoreKNN,KNNdata,colors) %mov = imported .avi move to be decorated %scoreJK = JK's manual scores %scoreBD = BD's manual scores %scoreKNN = scores generated by the KNN classifier %KNNdata = Nx45 array where N=number of frames, and 45 corresponds to the % raw data and higher order feature vectors. %colors = illustration colors in variable in legTrackerAnnotateColors.mat % movie dimensions H=360; W=690; %list of behavioral labels labels=cell(12,1); labels{1}='nothing'; labels{2}='postural adjust.'; labels{3}='fwd/bkwd running'; labels{4}='turning in place'; labels{5}='crabwalking'; labels{6}='complex motion'; labels{7}='L1 grooming'; labels{8}='head grooming'; labels{9}='L2-L3 grooming'; labels{10}='abdomen grooming'; labels{11}='L3 grooming'; labels{12}='other'; %start building image data image(zeros(H,W,3)+1) hold on; %composition parameters legScale=3; xOff=10; derivScale=5; stdScale=5; velScale=1; aceScale=1; % for 4000 frames for i=1:4000 %status indicator disp(i) %clear current figure clf; %start building image data image(zeros(H,W,3)+1); set(gca, 'visible', 'off') hold on; %add movie frame imTemp=read(mov,263+i); image(30,30,imTemp(1:200,36:end-20,:)); %add gray box labels N=20; plot([32+N/2 292-N/2], [270 270], 'Color', [.84 .84 .84], 'LineWidth', N); text(45,270,'video for manual scoring', 'FontSize', 15, 'FontWeight', 'bold'); plot([339+N/2 430-N/2], [263 263], 'Color', [.84 .84 .84], 'LineWidth', N-2); text(347,262,'raw data', 'FontSize', 15); plot([445+N/2 655-N/2], [263 263], 'Color', [.84 .84 .84], 'LineWidth', N-2); text(459,262,'higher order features', 'FontSize', 15); plot([340+N/2 654-N/2], [295 295], 'Color', [.84 .84 .84], 'LineWidth', N); text(389,295,'data for KNN classifier', 'FontSize', 15, 'FontWeight', 'bold'); %add manual scores - Comment these 4 lines out to make a movie without %manual scores text(36,300,'score(jk): ', 'FontSize', 15, 'FontWeight', 'bold'); text(130,300,labels{scoreJK(i)+1} , 'FontSize', 15, 'FontWeight', 'bold', 'Color', colors(scoreJK(i)+1,:) ); text(26,325,'score(bd): ', 'FontSize', 15, 'FontWeight', 'bold'); text(130,325,labels{scoreBD(i)+1} , 'FontSize', 15, 'FontWeight', 'bold', 'Color', colors(scoreBD(i)+1,:) ); %add classifier scores text(344,327,'score(KNN): ', 'FontSize', 15, 'FontWeight', 'bold'); text(466,327,labels{scoreKNN(i)+1} , 'FontSize', 15, 'FontWeight', 'bold', 'Color', colors(scoreKNN(i)+1,:) ); %add leg position label and indicator text(xOff+335,120,'leg positions ', 'FontSize', 12, 'FontWeight', 'bold'); scatter(xOff+365+KNNdata(i,9)*legScale,85+KNNdata(i,3)*legScale,'b.'); scatter(xOff+390+KNNdata(i,12)*legScale,85+KNNdata(i,6)*legScale, 'b.'); scatter(xOff+355+KNNdata(i,11)*legScale,65+KNNdata(i,5)*legScale,'b.'); scatter(xOff+400+KNNdata(i,8)*legScale,65+KNNdata(i,2)*legScale, 'b.'); scatter(xOff+365+KNNdata(i,7)*legScale,45+KNNdata(i,1)*legScale,'b.'); scatter(xOff+390+KNNdata(i,10)*legScale,45+KNNdata(i,4)*legScale, 'b.'); %add leg derivative label and indicator text(xOff+440,120,'leg derivatives', 'FontSize', 12, 'FontWeight', 'bold'); arrow([xOff+475 85],[xOff+475 85]-[KNNdata(i,39)*derivScale KNNdata(i,33)*derivScale],'Width', 1, 'TipAngle', 30, 'BaseAngle', 90, 'Length', 3, 'edgeColor', 'r', 'faceColor', 'r'); arrow([xOff+500 85],[xOff+500 85]-[KNNdata(i,42)*derivScale KNNdata(i,36)*derivScale],'Width', 1, 'TipAngle', 30, 'BaseAngle', 90, 'Length', 3, 'edgeColor', 'r', 'faceColor', 'r'); arrow([xOff+465 65],[xOff+465 65]-[KNNdata(i,41)*derivScale KNNdata(i,35)*derivScale],'Width', 1, 'TipAngle', 30, 'BaseAngle', 90, 'Length', 3, 'edgeColor', 'r', 'faceColor', 'r'); arrow([xOff+510 65],[xOff+510 65]-[KNNdata(i,38)*derivScale KNNdata(i,32)*derivScale],'Width', 1, 'TipAngle', 30, 'BaseAngle', 90, 'Length', 3, 'edgeColor', 'r', 'faceColor', 'r'); arrow([xOff+475 45],[xOff+475 45]-[KNNdata(i,37)*derivScale KNNdata(i,31)*derivScale],'Width', 1, 'TipAngle', 30, 'BaseAngle', 90, 'Length', 3, 'edgeColor', 'r', 'faceColor', 'r'); arrow([xOff+500 45],[xOff+500 45]-[KNNdata(i,40)*derivScale KNNdata(i,34)*derivScale],'Width', 1, 'TipAngle', 30, 'BaseAngle', 90, 'Length', 3, 'edgeColor', 'r', 'faceColor', 'r'); %add ellipse representation of local x- and y- standard deviations of %leg position text(xOff+560,120,'std(leg pos)', 'FontSize', 12, 'FontWeight', 'bold'); ellipse(KNNdata(i,24)*stdScale,KNNdata(i,18)*stdScale,0,587,85,[.5 .5 .5]); ellipse(KNNdata(i,27)*stdScale,KNNdata(i,21)*stdScale,0,612,85,[.5 .5 .5]); ellipse(KNNdata(i,26)*stdScale,KNNdata(i,20)*stdScale,0,577,65,[.5 .5 .5]); ellipse(KNNdata(i,23)*stdScale,KNNdata(i,17)*stdScale,0,622,65,[.5 .5 .5]); ellipse(KNNdata(i,22)*stdScale,KNNdata(i,16)*stdScale,0,587,45,[.5 .5 .5]); ellipse(KNNdata(i,25)*stdScale,KNNdata(i,19)*stdScale,0,612,45,[.5 .5 .5]); % add ball 3-axis velocity labels and data values text(xOff+335,225,'ball velocity', 'FontSize', 12, 'FontWeight', 'bold'); plot(xOff+345+[0 0], 178-[0 KNNdata(i,14)*velScale], 'r', 'LineWidth',4) text(xOff+335,190,'fwd', 'FontSize', 10, 'FontWeight', 'bold'); plot(xOff+375+[0 0], 178-[0 KNNdata(i,13)*velScale], 'k', 'LineWidth',4) text(xOff+365,190,'turn', 'FontSize', 10, 'FontWeight', 'bold'); plot(xOff+405+[0 0], 178-[0 KNNdata(i,15)*velScale], 'g', 'LineWidth',4) text(xOff+395,190,'crab', 'FontSize', 10, 'FontWeight', 'bold'); % add ball 3-axis acceleration labels and data values text(xOff+440,225,'ball accelerat.', 'FontSize', 12, 'FontWeight', 'bold'); arrow([xOff+457 178], [xOff+457 178-KNNdata(i,44)*aceScale],'Width', 2, 'TipAngle', 45, 'BaseAngle', 90, 'Length', 3, 'edgeColor', 'r', 'faceColor', 'r'); text(xOff+447,190,'fwd', 'FontSize', 10, 'FontWeight', 'bold'); arrow([xOff+487 178], [xOff+487 178-KNNdata(i,43)*aceScale],'Width', 2, 'TipAngle', 45, 'BaseAngle', 90, 'Length', 3, 'edgeColor', 'k', 'faceColor', 'k'); text(xOff+477,190,'turn', 'FontSize', 10, 'FontWeight', 'bold'); arrow([xOff+517 178], [xOff+517 178-KNNdata(i,45)*aceScale],'Width', 2, 'TipAngle', 45, 'BaseAngle', 90, 'Length', 3, 'edgeColor', 'g', 'faceColor', 'g'); text(xOff+507,190,'crab', 'FontSize', 10, 'FontWeight', 'bold'); %add ball 3-axis local standard deviations labels and values text(xOff+560,225,'std(ball vel)', 'FontSize', 12, 'FontWeight', 'bold'); plot(xOff+571+[0 0], 178-[0 KNNdata(i,29)*velScale], 'r', 'LineWidth',4) text(xOff+561,190,'fwd', 'FontSize', 10, 'FontWeight', 'bold'); plot(xOff+601+[0 0], 178-[0 KNNdata(i,28)*velScale], 'k', 'LineWidth',4) text(xOff+591,190,'turn', 'FontSize', 10, 'FontWeight', 'bold'); plot(xOff+631+[0 0], 178-[0 KNNdata(i,30)*velScale], 'g', 'LineWidth',4) text(xOff+621,190,'crab', 'FontSize', 10, 'FontWeight', 'bold'); %pause to update screen and buffer pause(0.01); %grab image to movie output. movie1(i)=getframe; end out=movie1;