%% Setting up...
w = 1280;
h = 720;
nframes = 500;
%videos = [1 7 8 9 10 11 12];
videos = [8 9];

%% Open each original video sequence (e.g. each different video [v1, v7, ...]
for vF = 1 : length(videos)
    filename_in = dir(strcat('../../VideosYUV/blkblr_v',num2str(videos(vF)),'_*_0.yuv'));
    in_size = size(filename_in,1);

    %% Load all test sequences regarding the original video
    for inF = 1 : in_size
    filename_rf = dir(strcat('../../VideosYUV/',filename_in(inF).name(1:10),'*.yuv'));
    rf_size = size(filename_rf,1);
    
    %% Open original video
    [org] = yuv_import(strcat('../../VideosYUV/',filename_in(inF).name),[w h],nframes);
    
        %% open original vs each test sequence videos
        for inR = 1 : rf_size       
            %% Open the files
            [ref] = yuv_import(strcat('../../VideosYUV/',filename_rf(inR).name),[w h],nframes);
            %% Read each frames of the videos
            for n = 1 : nframes
                img1 = org{1,n};
                img2 = ref{1,n};
                [mssim] = ssim_index(img1, img2);
                a(n) = mssim;
                ssim = mean(a);
            end
            % Save weights of SSIM
            fid = fopen(strcat(filename_in(inF).name(1:end-4),'_SSIM.txt'),'a');
            fprintf(fid, '%s: %f\n', filename_rf(inR).name, ssim);
            fclose all;
            disp (strcat('Done:',num2str(inR),'_of_', num2str(rf_size)))
        end
    end
end
clear all