% =========================================================================
% Nonlocal Autoregressive Modeling based image interpolation, Version 1.0
% Copyright(c) 2013 Weisheng Dong, Lei Zhang, Guangming Shi
% All Rights Reserved.
%
% ----------------------------------------------------------------------
% Permission to use, copy, or modify this software and its documentation
% for educational and research purposes only and without fee is here
% granted, provided that this copyright notice and the original authors'
% names appear on all copies and supporting documentation. This program
% shall not be used, rewritten, or adapted as the basis of a commercial
% software or hardware product without first obtaining permission of the
% authors. The authors make no representations about the suitability of
% this software for any purpose. It is provided "as is" without express
% or implied warranty.
%----------------------------------------------------------------------
%
% This is an implementation of the algorithm for image interpolation
% 
% Please cite the following paper if you use this code:
%
% Weisheng Dong, Lei Zhang, R. Lukac, and G. Shi,"Sparse representation based
% image interpolation with nonlocal autoregressive modeling", IEEE Trans. on
% Image Processing, vol. 22, no. 4, pp. 1382-1394, Apr. 2013.
% 
%--------------------------------------------------------------------------
%clc;
clear;
warning off all

fn               =    'Data\Test_images\girl.tif';
scale            =     3;    % Scaling factors: 2, 3

par              =    Parameters_setting( scale );
par.I            =    double( imread( fn ) );    
LR               =    par.I(1:scale:end,1:scale:end,:);    
par.LR           =    Add_noise(LR, par.nSig);   
par.B            =    Set_delta_matrix( par );    
    
[im PSNR SSIM bic_im]    =    NARM_Superresolution( par );
    
imwrite(im./255, 'Results\NARM_x2_girl.tif');
imwrite(bic_im./255, 'Results\bic_x2_girl.tif');       
