% Eventually this function will be a specific postprocesing routine, 
%but right now I am just trying a couple of things.


load S264_interout.mat
load S325_interout

%integrate over window of 11 frames. 
%  for i = 6:(size(AUout,1)-5)
%     AUout2((i-5),:) = sum(AUout([(i-5):(i+5)],:));
%  end
%AUout = [AUout(1:5,:);AUout2;AUout((end-4):end,:)];


  %Neutral frames: Frame 7000 is neutral right after interviwere sits down. 
  %650 to 700 are all pretty neutral. (660)
%Also frame 10000 Frame 11800
  % I will choose 660 and 1000, and take mean. ( mean[650:685] isn't good)

  %neutOut = mean(AUout([650:685],:)); no good
neutOut = mean(AUout([660,1000],:);

mu = mean(Results(:,2:9)) %(just subtract the mean)
sd = std( Results(:,2:9));
%The neutral response is within 0.1 of the mean response. 

%AUout = AUout - ones(size(AUout,1),1)*neutOut;
AUout = AUout - ones(size(AUout,1),1)*mu;

%This version converts to Z-score. It looks terrible!
%tmp = ones(size(AUout,1),1)*sd;
%AUout = AUout./tmp; 

%When face is not found, make output lower than all else. 
[i,j] = find(facefound == 0);
AUout(j,:)=AUout(j,:)-5;


Results=write_resultfiles('S325_postproc_',EyePosn,AUout,imNames,facefound);

imgdir = '/RAID4/NRL/D005-TestSubjects/S325_inter';
M = make_demo2(EyePosn,AUout,imgdir,imNames,2000,2200);

% View a matlab version of the movie:
clf reset
tmp = frame2im(M(1));imshow(tmp); %Expands the window
movie(M,2)                        %Play movie twice

