function I=den_bayernoise(In,vr,vg,vb);

rIn(:,:)=In(:,:,1);
gIn(:,:)=In(:,:,2);
bIn(:,:)=In(:,:,3);

Ir=den_bayer(rIn,vr,vg,vb);
Ig=den_bayer(gIn,vr,vg,vb);
Ib=den_bayer(bIn,vr,vg,vb);

Ir = round(Ir); 
ind = find(Ir>2^8-1); 
Ir(ind) = 2^8-1; 
ind = find(Ir<0); 
Ir(ind) = 0; 

Ig = round(Ig); 
ind = find(Ig>2^8-1); 
Ig(ind) = 2^8-1; 
ind = find(Ig<0); 
Ig(ind) = 0; 

Ib = round(Ib); 
ind = find(Ib>2^8-1); 
Ib(ind) = 2^8-1; 
ind = find(Ib<0); 
Ib(ind) = 0; 

I(:,:,1)=Ir;
I(:,:,2)=Ig;
I(:,:,3)=Ib;

return;

function A=den_bayer(In,vr,vg,vb)
[ld,hd,lr,hr]=wfilters('db4');
J=3;
[S,HW,WH,WW] = denocwt2d(ld,hd,J,In,vr,vg,vb);
A=iocwt2d(S,HW,WH,WW,lr,hr);
return;
