
%--------------------------- Load Parameters ----------------------------------

%run_Bregman

params = loadParameters_Breg();


orim = params{1};

     [f0]=(imread(orim));
[vf hf d]=size(f0);
if d==3
     f0=rgb2gray(f0);
end


iter_c_grad =str2num(params{12});
f0=double(f0);

[vF hF]=size(f0);
IND=str2num(params{2});
DeTr = str2num(params{3});

no_Breg_iter = str2num(params{4});
lamu = str2num(params{5});
lambda=lamu(1);
muu=lamu(2);

span_kern =str2num(params{7});
if params{6}=='ga';
 ker = fspecial('gaussian',[span_kern(1), span_kern(1)],span_kern(2));ker=double(ker);   
   elseif params{6}=='mo';
   ker=fspecial('motion',span_kern(1), span_kern(2));
end
ker=double(ker); 
F1=conv2(f0,ker,'same');

std_nois=str2num(params{9});
if params{10}=='y'
    nois=std_nois*randn(vF);
end
F2=F1+nois;
[v2,h2]=size(F2);

if params{11}=='y'
percent_loss=str2num(params{8});

 vh=v2*h2;   
i_I=randperm(vh);

kk=round((percent_loss/100)*vh);
IND_noise=i_I(1,1:kk);

end

 F3=F2;   
F3(IND_noise)=0;

 FF3=F2;   
FF3(IND_noise)=255;


[lv,lh]=size(F3);
HMWF=hmwf(IND,DeTr,lv,lh);

 
uk  =zeros(size(F3));
bk=fram34_dec2d_hmwf(uk,DeTr,IND,HMWF);
dk=bk;


r1=conv2(F3,ker','same' );
tic
for iii=0:no_Breg_iter 
    iii
    
[uk,dk,bk]=BREGMAN_INPAINT_DEBLU_hm(IND_noise,r1,dk,bk,ker,DeTr,IND,muu,lambda,iter_c_grad,HMWF);

end
toc
[ve, ho]=size(uk);


display_breg