%
% Copyright (c) 2011, Kai Guo, Prakash Ishwar, and Janusz Konrad. All
% rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% 1) Redistributions of source code must retain the above copyright
%    notice, this list of conditions and the following disclaimer.
%
% 2) Redistributions in binary form must reproduce the above copyright
%    notice, this list of conditions and the following disclaimer in the
%    documentation and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
% "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
% LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
% A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
% HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
% SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
% LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
% DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
% THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
% OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%

% compare every video cube (8 frames) with all the other video cubes in the
% database
clear
clc

load classification_masks.mat

flag='aligned';
name={'daria';'denis';'eli';'ido';'ira';'lena';'lyova';'moshe';'shahar'};
act={'bend';'jack';'jump';'pjump';'run';'side';'skip';'walk';'wave1';'wave2'};

cube_length=20;
jump_dataset=4;

% extract the feature of database seq:
Cov_dataset_all=cell(9,10);
MU_dataset_all=cell(9,10);

flag_smooth = 0; % flag that is used to fill in holes and reduce noise.

for i=1:9
    i
    for j=1:10
         seq2=eval([flag,'_masks.',char(name(i)),'_',char(act(j))]);
         
         if flag_smooth
             for k=1:size(seq2,3)
                 seq2(:,:,k)=imfill(seq2(:,:,k),'holes');
             end
             seq2=medfilt3(seq2,5,5,1);
         end
         
         % N is the number of cubes in the seq
         N=floor((size(seq2,3)-cube_length)/jump_dataset+1);
         
         Cov_dataset=zeros(13,13,N);
         MU_dataset=zeros(N,13);
         for k=1:N
             seq_dataset=seq2(:,:,jump_dataset*(k-1)+1:jump_dataset*(k-1)+cube_length);
             [Cov_dataset(:,:,k),MU_dataset(k,:)]=video_3D_hor_ver_dis_bounday_single(seq_dataset);
         end
         Cov_dataset_all{i,j}=Cov_dataset;
         MU_dataset_all{i,j}=MU;
    end
end

%%%%%%%%
