clear
clc


dir='C:\Documents and Settings\ruigangfang\My Documents\MATLAB\3d\database\livephase2\Phase2';
load ([dir,'\3DDmosRelease.mat'])


[mm,nn]=size(Dmos);

dir_save='C:\Documents and Settings\ruigangfang\My Documents\MATLAB\3d\disparity_method4\data\phase2';
load ([dir_save,'\cyclopean_image\index.mat']);
%dir_save=[dir_save,'\cyclopean_image\'];

%dir_save=[dir_save,'\disparity_similarity_L\'];
%dir_save=[dir_save,'\disparity_similarity_R\'];
%dir_save=[dir_save,'\weight\'];

num=[];
type=[0:4] ;% 0: noise, 1: jpeg2k, 2: jpeg, 3: gaussian blur, 4: fast-fading
for i=1:max(size(type))
    tt=[1:9]+9*type(i);%% [4 7 9]
    tt=[tt,45+tt,2*45+tt,3*45+tt,4*45+tt,5*45+tt,6*45+tt,7*45+tt];
    num=[num,tt];
end
%%
%num=[1:9]+9*4;
%%
% num=[1:360];
% k=0;

for i=1:max(size(num))
    i/max(size(num))
    %% for cyclopean image read
    load ([dir_save,'\cyclopean_image\',num2str(num(i)),'.mat']);
    %% for img_l and img_r
    img=imread([dir,'\Stimuli\',StiFilename{num(i)}]);
    [m,n,t]=size(img);
    img_l=img(:,1:n/2,:);
    img_r=img(:,n/2+1:n,:);
    %% for dis_l and dis_r
    load ([dir_save,'\disparity_similarity_L\',num2str(num(i)),'.mat']);
    dis_l=data{1};
    ss2_l=data{2};
    ss3_l=data{3};
    ss4_l=data{4};
    clear data
    load ([dir_save,'\disparity_similarity_R\',num2str(num(i)),'.mat']);
    dis_r=data{1};
    ss2_r=data{2};
    ss3_r=data{3};
    ss4_r=data{4};
    clear data
    %% for weight
    load ([dir_save,'\weight\',num2str(num(i)),'.mat']);
    %%
%     f(i,1:6)=f_cyc_block(image,img_l,img_r,dis_l,dis_r,index(num(i)),weight);
%     f(i,7)=f_cyc_blur_o0_n0(image,img_l,img_r,dis_l,dis_r,index(num(i)),weight);
%     f(i,8)=f_cyc_blur_o0_n1(image,img_l,img_r,dis_l,dis_r,index(num(i)),weight);
%     f(i,9)=f_cyc_blur_o1_n0(image,img_l,img_r,dis_l,dis_r,index(num(i)),weight);
%     f(i,10:12)=f_cyc_blur_o1_n1(image,img_l,img_r,dis_l,dis_r,index(num(i)),weight);
%     f(i,13:14)=f_cyc_disparity_gradient(image,img_l,img_r,dis_l,dis_r,index(num(i)),weight);
%     f(i,15:20)=f_cyc_gradient(image,img_l,img_r,dis_l,dis_r,index(num(i)),weight);
%     f(i,21:26)=f_pairs_block(image,img_l,img_r,dis_l,dis_r,index(num(i)),weight);
%     f(i,27:28)=f_weight(image,img_l,img_r,dis_l,dis_r,index(num(i)),weight);
%     f(i,29:34)=f_dis_difference(image,img_l,img_r,dis_l,dis_r,index(num(i)),weight);
%     f(i,35:37)=f_pair_blur_o1_n1(image,img_l,img_r,dis_l,dis_r,index(num(i)),weight);
%     f(i,38:41)=f_rivalry(ss2_l,ss2_r,index,Dmos(num(i)));
%     f(i,42:45)=f_rivalry(ss3_l,ss3_r,index,Dmos(num(i)));
%     f(i,46:49)=f_rivalry(ss4_l,ss4_r,index,Dmos(num(i)));
    f(i,50:51)=f_cyc_disparity_neighbor(image,img_l,img_r,dis_l,dis_r,index(num(i)),weight);
    %%
    score(i)=Dmos(num(i));
    
    %% depth map
    %   if index(num(i))==1
    %       disparity=dis_l;
    %   else
    %       disparity=dis_r;
    %   end
    %   maxs=max(max(disparity));
    %   mins=min(min(disparity));
    %   disparity=(disparity-mins)/(maxs-mins)*255;
    %   k=k+1;
    %   figure(k)
    %   imshow(uint8(disparity))
    %%
    %     ss=rivalry(ss2_l,ss2_r,index);
    %     subplot(3,3,k)
    %     k=k+1;
    %     hist(ss(:),[0:0.01:1])
    %     xlabel([num2str(Dmos(num(i))),'   ',num2str(mean2(weight))]);
    %%
    
    %     k=k+1;
    %     figure(k)
    %     imshow(image)
end

for i=50:51
    cf(i-49,1)= corr(f(:,i),score','type','spearman');
end

%cf1= corr(f(:,1),score','type','spearman')
% %  cf2= corr(f(:,2),score','type','spearman')
%plot(f,score,'b.')
%hold on












