%     close all;
    clear all;
    addpath(genpath('Data\'));
    addpath(genpath('Utilize\'));
    nSig = 20;
    ratio = 0.3;
    %     [filename, filepath, FilterIndex ] = uigetfile('data/*.*','Read image');
    %     O_Img =  double(imread(fullfile(filepath,filename))) ;

    load('G:\My paper\2018TIP--Hyperspectral Image Restoration--Where Does the Low-Rank Property Exist\Data\PaviaU.mat')
    O_Img = paviaU(1:340,:,73:103);
    O_Img = O_Img/32;
    max_O_Img = max(O_Img(:));
    min_O_Img = min(O_Img(:));
    O_Img = 256*(O_Img - min_O_Img) / (max_O_Img - min_O_Img);

%% Generate the mask
   MaskType = 1; % 1 for random mask; 2 for text mask; 3 for stripe mask ; 4 for real images
   switch MaskType
       case 1
           ratio = 0.01;
           rand('seed',0);
           randn('seed',0);
           O = ones(size(O_Img));
           O =  Line_Mask(O,0.5,0);
%            O = double(rand(size(O_Img)) > (1-ratio));
       case 2
           O = imread('TextMask256.png');
           %         O(O==0)=255;
           %         O(O==1)=0;
           O = double(O>128);
       case 3
           O = ones(size(O_Img));
           for i = 1:10:250
               O(:,i+3) =  0;
               O(:,i+5) =  0;
               O(:,i+4) =  0;
           end
       case 4
           O = ones(size(O_Img));
           O(O_Img < 100)=0;
   end

    randn('seed', 0);
    N_Img = O_Img.* O + 0* randn(size(O_Img));                                   %Generate noisy image
    PSNR  =  csnr( N_Img, O_Img, 0, 0 );
    SSIM  = cal_ssim( N_Img, O_Img, 0, 0 ); 
    fprintf( 'Noisy Image: nSig = %2.3f, PSNR = %2.2f, SSIM = %2.3f,\n\n\n', nSig, PSNR,SSIM );
    
    Par   = ParSet_Inpainting(nSig,ratio);       
   [E_Img]= LRTR_Inpainting( N_Img, O_Img, O, Par);  %LRTA inpainting function
    PSNR  =  csnr( O_Img, E_Img, 0, 0 );
    SSIM  = cal_ssim( O_Img, E_Img, 0, 0 ); 
    SAM   = SpectAngMapper(O_Img,E_Img);
    ERGAS = ErrRelGlobAdimSyn(O_Img, E_Img);
    fprintf( sprintf('%s: PSNR = %3.2f  SSIM = %f SAM = %f, ERGAS = %f \n','PaviaU', PSNR, SSIM, SAM, ERGAS) );


