
% auxiliary procedure for RWTnose.
% image noise reduction by level dependent thresholding
% and non-decimated wavelet transform(RWT) (+ GCV - estimation)

% 2D redundant wavelet transform (RWT)

wcoef = RWT2_BIO(img,M,ht,gt,sht,sgt);
wout = wcoef;
label = zeros(size(wcoef));

for j = 1:M
j
  % horizontal component

  x = zeros(size(img));
  x(:,:) = wcoef(j,1,:,:);
  [y, thr] = mingcv2(x);
  wout(j,1,:,:) = y;
  label(j,1,:,:) = (abs(x) > thr);
  gcvthr(j,1) = thr;

  % vertical subband

  x = zeros(size(img));
  x(:,:) = wcoef(j,2,:,:);
  [y, thr] = mingcv2(x);
  wout(j,2,:,:) = y;
  label(j,2,:,:) = (abs(x) > thr);
  gcvthr(j,2) = thr;

  % diagonal subband

  x = zeros(size(img));
  x(:,:) = wcoef(j,3,:,:);
  [y, thr] = mingcv2(x);
  wout(j,3,:,:) = y;
  label(j,3,:,:) = (abs(x) > thr);
  gcvthr(j,3) = thr;

end

% inverse transform

imgout = IRT2_BIO(wout,h,g,sh,sg,0.5);

figure(2); image(imgout); colormap(imgmap)
title('level dependent GCV threshold')
