clear;
nameList=getList([getenv('datafolder') '/MRI/ground truth/*.mat']);
% nameList={'lunges'};
% nameList={'lena','airplane','peppers','facade','house','sailboat'};
for i=1:length(nameList)
    name=nameList{i};
    %% ground truth
    [data,type,folder]=input_helper(name);
    fprintf('Test on %s(%s):\n\n',name,type); 
    s1='%20s\t%8s\t%8s\t%12s\n';
    fprintf(s1,'observed percent','PSNR','RSE','time cost');
    % fprintf('%24s\t%2s\t%14s\t\t%5s\t%7s\n','Fidelity','S','Objective','PSNR','DIFF');
    %% Chosing Parameters
    switch type % About stepsize and patchsize: dim%stepsize=patchsize%stepsize
        case 'gray-images'
            stepsize=[1 1];
            patchsizeE=[5 5];
            patchsizeF=[3 3];
            lambda=1e-4;
        case 'color-images'
            p=0.4:0.1:0.9; %SR for color image
            stepsize=[1 1 1];
            patchsizeE=[5 5 1];
            patchsizeF=[3 3 3];
            lambda=5*1e-4;
            gamma=1.05;
            batchsize = -1;
        case 'videos'
            p=0.1:0.1:0.9;%sampling rate
            stepsize=[4 4 4];
            patchsizeE=[10 10 1];
            patchsizeF=[7 7 4];
            lambda=5*1e-2;
            gamma = 1.1;
            batchsize = 5000;
        case 'MRI'
            p=0.1:0.1:0.9;%sampling rate
            stepsize=[5 5 4];
            patchsizeE=[8 8 3];
            patchsizeF=[5 5 5];
            lambda=5*1e-1;
            gamma = 1.1;
            batchsize=5000;
        case 'MSI'
            p=0.1:0.1:0.3;%sampling rate      
            stepsize=[7 7 7];
            patchsizeE=[8 8 6];
            patchsizeF=[4 4 5];
            lambda=1*1e-1;
            gamma = 1.1;
            batchsize=5000;

    end
%     p=0.9:-0.1:0.3;
    % p=[0.9 0.4];
    p=0.2:0.1:0.9;
    for ratio=p
        %% Input data
        dim     = size(data);
        Y       = data;
        file    = [folder '/SR=' num2str(ratio) '/' num2str(ratio),'chosen_' ,name,'.mat']; %% load the incomplete data
        load(file)   
%         Y       = data;
        Y       =  zeros(size(data));
        Y(chosen)= data(chosen);
        %% Setting Parameters
        params.stepsize    = stepsize;
        params.patchsizeE  = patchsizeE;
        params.patchsizeF  = patchsizeF;
        params.lambda      = lambda;
        params.gamma       = gamma;
        params.batchsize   = batchsize;
        params.max_Iter    = 500;
        params.epsilon     = 1e-4;
        params.ratio       = ratio;
        params.name        = [type '/' name];
        params.savepath    = [getenv('resultfolder') '/' mfilename '/'];
        %%
        [X , LOG ]    = DOTC_cpu(Y,chosen,params);
        %%
        X_dif       = data-X;
        RSE         = 20*log10(norm(X_dif(:))/norm(data(:)));
        MSE         = (norm(X_dif(:))^2)/(prod(dim));
        PSNR        = 10*log10(255^2/MSE);
        fprintf('%13.1f\t%17.2f\t%9.2f\t%10.2f\n',ratio,PSNR,RSE,LOG.time);
    end
end