%===========================================================
%
%        FILE: debluring_data.m
%  Written by: Joao Oliveira
% Last review: Sep 2009 
%         WWW: http://www.lx.it.pt/~jpaos/
%
%===========================================================
% Description: 
%
% This file runs and generate data for experience 
% number 'exp' from paper: 
%
% João P. Oliveira, José M. Bioucas-Dias, Mário A.T. Figueiredo, 
% "Adaptive total variation image deblurring: A
% majorization?minimization approach",  Signal Processing,
% Volume 89, Issue 9, September 2009, Pages 1683-1693. 
%
%===========================================================

% Warning: in the paper, by a missprint, the results in table 1
%          of experiments 2 and 3 are swapped.
%


clear;


% experiments to run
 
experiments=[5];

% save data ? 
savedata=1;

% sufix to append to data file
sufixo='_final02';


% Load the same random state so that
% experiments are reproducible
load random_state;



% MM simulation parameters
MM_iter=10;
MM_thrld=1e-2;
S_iter=5;
S_thrld=1e-5;
CG_iter=100;
CG_thrld=1e-5;

lambda=[];
for exp = experiments

    
    % Load experiments setup
    setup_experiments;

    
%     fprintf('Simulation picture = %s\tSigma = %g, alpha = %g, beta = %g, elambda = %g\n',imagem,sigma,1,1,0.064*sigma^2);
    
    % Set random seed
    randn('state',state);
    
    img_ruido=conv2c(img,h)+sigma*randn(size(img));

    x0=128*randn(size(img));
    
    options={'image',img,'displayIm','yes',...
        'info_ISNRo','yes','info_energyo','yes',...
        'sigma',sigma,'x_0',x0,...
        'MM_iter',MM_iter,...
        'MM_thrld',MM_thrld,...
        'S_iter',S_iter,...
        'S_thrld',S_thrld,...
        'CG_iter',CG_iter,...
        'CG_thrld',CG_thrld,...
        'theta',theta};

   [img_tv2,energyi,ISNRi,energyo,ISNRo,lambda]=tvmm(img_ruido,h,options);
   
   if savedata
       dados_imagem=strcat(dados,'_exp_',num2str(exp),sufixo,'.mat');
       save(dados_imagem);
   end


    
end



