%conv_exa2_stdP
%  regularization with fixed sampling, std 5, 20
NS=20;%input('noise scaling --?')


load BLO
barle=input('Barbara--1; Lena --2;  ?')
if barle==1
bloch=blochB;
elseif barle==2
bloch=blochL;
end
Par=4;
q=2;
deci=2;

lev=log2(deci);
ToX=.00000001;
range_rho1=10000;%input('range_rho1; 111-former; ?')
if range_rho1~=111
    range_rho=[0 range_rho1];
end

F=bloch;
%y=bl;
[M,~]=size(bloch);
D=(1:deci:M);
sg1=1;%input('gauss--1;savitzky--2; std--3; heat--5;0 --none; ?')
if sg1>0
    sg=sg1;
end
  t1 = input('stretch of kernel;111 --former; ?')
if t1~=111
    t=t1;
end

[H,fH]=buikerP(M,t,sg);%build kernel
fF=fft2(F);
    fG=fF.*fH;
    G=real(ifft2(fG));


st1=input('noise std; 111-former; ?')
if st1~=111
    st=st1;
    nois=st*randn(M);
end
Z=G+nois;



figure;
subplot(2,2,1)
noi=nois(D,D);
z=Z(D,D);
f=F(D,D);
h=H(D,D);
ee=sum(noi(:).^2);
  [uq,~]=juviP(q,M/deci); 
 uq=uq'*uq;
 mu=fft2(h)./uq;
      rho=defroP_conv(Par,q,z,mu,ee,range_rho,ToX)
  %rho=.1    
s=convsplaP2(z,Par,q,mu,lev,rho) /4^lev;

[PSNR_z ,mablod]=psnB(f,z);
ai(z);
ste=256/deci;
set(gca,'YTick',0:ste:2*ste);set(gca,'YTickLabel',{'0','256','512'})
set(gca,'XTick',0:ste:2*ste);set(gca,'XTickLabel',{'0','256','512'})
title(['\fontsize{16}Sampl=1:' int2str(deci) ', STD=' num2str(st) ', PSNR=' num2str(PSNR_z,4 ) ])
set(gca,'Fontsize',16)
subplot(2,2,2)
[PSNR mablod]=psnB(F,s);

ai(s)
title(['\fontsize{16}Spl. order: '  int2str(Par) ', PSNR=' num2str(PSNR,4 ) ', \rho=' num2str(rho,2) ])
%title(['\fontsize{16}\rho=' num2str(rho)])
set(gca,'YTick',0:256:512);set(gca,'YTickLabel',{'0','256','512'})
set(gca,'XTick',0:256:512);set(gca,'XTickLabel', {'0','256','512'})
set(gca,'Fontsize',16)

subplot(2,2,3)

noi=NS*nois(D,D);
z=G(D,D)+noi;
ee=sum(noi(:).^2);
   %rho=defroPCo(Par,q,z,h,ee,range_rho,ToX,regg)
 rho=defroP_conv(Par,q,z,mu,ee,range_rho,ToX)
s=convsplaP2(z,Par,q,mu,lev,rho) /4^lev;

[PSNR_z mablod]=psnB(f,z);
ss=round(std(noi(:)))
ai(z);
ste=256/deci;
set(gca,'YTick',0:ste:2*ste);set(gca,'YTickLabel',{'0','256','512'})
set(gca,'XTick',0:ste:2*ste);set(gca,'XTickLabel',{'0','256','512'})
title(['\fontsize{16}Sampl=1:' int2str(deci) ', STD=' num2str(ss) ', PSNR=' num2str(PSNR_z,4 )])
set(gca,'Fontsize',16)
subplot(2,2,4)
[PSNR mablod]=psnB(F,s);

ai(s)
title(['\fontsize{16}Spl. order: '  int2str(Par) ', PSNR=' num2str(PSNR,4 ) ', \rho=' num2str(rho,2) ])
%title(['\fontsize{16}\rho=' num2str(rho)])
set(gca,'YTick',0:256:512);set(gca,'YTickLabel',{'0','256','512'})
set(gca,'XTick',0:256:512);set(gca,'XTickLabel', {'0','256','512'})
set(gca,'Fontsize',16)



