hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_wav_2d_coeff_ext (c09ey)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_wav_2d_coeff_ext (c09ey) extracts a selected set of discrete wavelet transform (DWT) coefficients from the full set of coefficients stored in compact form, as computed by nag_wav_2d_multi_fwd (c09ec) (two-dimensional DWT).

Syntax

[d, icomm, ifail] = c09ey(ilev, cindex, c, icomm, 'lenc', lenc)
[d, icomm, ifail] = nag_wav_2d_coeff_ext(ilev, cindex, c, icomm, 'lenc', lenc)

Description

nag_wav_2d_coeff_ext (c09ey) is intended to be used after a call to nag_wav_2d_multi_fwd (c09ec) (two-dimensional DWT), which in turn should be preceded by a call to nag_wav_2d_init (c09ab) (two-dimensional wavelet filter initialization). Given an initial two-dimensional data set A, a prior call to nag_wav_2d_multi_fwd (c09ec) computes the approximation coefficients (at the highest requested level) and three sets of detail coeficients at all levels and stores these in compact form in a one-dimensional array c. nag_wav_2d_coeff_ext (c09ey) can then extract either the approximation coefficients or one of the sets of detail coefficients at one of the levels into a matrix D. The dimensions of D depend on the level extracted and are available from the arrays dwtlvm and dwtlvn as returned by nag_wav_2d_multi_fwd (c09ec) which contain the first and second dimensions respectively. See Multiresolution and higher dimensional DWT in the C09 Chapter Introduction for a discussion of the two-dimensional DWT.

References

None.

Parameters

Note: the following notation is used in this section:

Compulsory Input Parameters

1:     ilev int64int32nag_int scalar
The level at which coefficients are to be extracted.
Constraints:
2:     cindex int64int32nag_int scalar
Identifies which coefficients to extract. The coefficients are identified as follows:
cindex=0
The approximation coefficients, produced by application of the low pass filter over columns and rows of the original matrix (LL). The approximation coefficients are available only for ilev=nwl, where nwl is the value used in a preceding call to nag_wav_2d_multi_fwd (c09ec).
cindex=1
The vertical detail coefficients produced by applying the low pass filter over columns of the original matrix and the high pass filter over rows (LH).
cindex=2
The horizontal detail coefficients produced by applying the high pass filter over columns of the original matrix and the low pass filter over rows (HL).
cindex=3
The diagonal detail coefficients produced by applying the high pass filter over columns and rows of the original matrix (HH).
Constraint: 0cindex3 when ilev=nwl as used in nag_wav_2d_multi_fwd (c09ec), otherwise 1cindex3.
3:     clenc – double array
DWT coefficients, as computed by a preceding call to nag_wav_2d_multi_fwd (c09ec).
4:     icomm180 int64int32nag_int array
Contains details of the discrete wavelet transform and the problem dimension as setup in the call to the initialization function nag_wav_2d_init (c09ab).

Optional Input Parameters

1:     lenc int64int32nag_int scalar
Default: the dimension of the array c.
The dimension of the array c.
Constraint: lenc must be unchanged from the value used in the preceding call to nag_wav_2d_multi_fwd (c09ec)..

Output Parameters

1:     dldd: – double array
The first dimension of the array d will be ncm.
The second dimension of the array d will be ncn.
The requested coefficients.
If ilev=nwl (as used in nag_wav_2d_multi_fwd (c09ec)) and cindex=0, the ncm by ncn approximation coefficients aij are stored in dij, for i=1,2,,ncm and j=1,2,,ncn.
Otherwise the ncm by ncn level ilev detail coefficients (of type specified by cindex) dij are stored in dij, for i=1,2,,ncm and j=1,2,,ncn.
2:     icomm180 int64int32nag_int array
Communication array, used to store information between calls to nag_wav_2d_coeff_ext (c09ey).
3:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
   ifail=1
Constraint: ilevnwl, where nwl is the number of levels used in the call to nag_wav_2d_multi_fwd (c09ec).
Constraint: ilev1.
   ifail=2
Constraint: cindex3.
Constraint: cindex0.
   ifail=3
Constraint: lencnct, where nct is the number of DWT coefficients computed in a previous call to nag_wav_2d_multi_fwd (c09ec).
   ifail=4
Constraint: lddncm, where ncm is the number of DWT coefficients in the first dimension at the selected level ilev.
   ifail=5
Constraint: cindex>0 when ilev<nwl in the preceding call to nag_wav_2d_multi_fwd (c09ec).
   ifail=6
Either the initialization function has not been called first or icomm has been corrupted.
Either the initialization function was called with wtrans='S' or icomm has been corrupted.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

Not applicable.

Further Comments

None.

Example

See Example in nag_wav_2d_init (c09ab), nag_wav_2d_multi_fwd (c09ec) and nag_wav_2d_coeff_ins (c09ez).
function c09ez_example


fprintf('c09ey example results\n\n');

% 2D Data
m = int64(7);
n = int64(6);
a = zeros(m,n);
a(1:2:m,:) = 0.01;
a(2:2:m,:) = 1;

% Add Noise
genid = int64(3);
subid = int64(0);
seed(1) = int64(642521);
[state, ifail] = g05kf(genid, subid, seed);
[state, x, ifail] = g05sk(m*n, 0, 1.0e-4, state);
an = a + reshape(x,[m,n]);

fprintf('\nInput data a:\n');
disp(a);
fprintf('\nNoisy data an:\n');
disp(an);

% Wavelet setup
wavnam = 'DB6';
mode = 'Period';
wtrans = 'Multilevel';
[nwl, nf, nwct, nwcn, icomm, ifail] = ...
  c09ab(...
        wavnam, wtrans, mode, m, n);

% Multi-level wavelet transform on noisy data
lenc = nwct;
% Perform Discrete Wavelet transform
[c, dwtlvm, dwtlvn, icomm, ifail] = ...
  c09ec(...
        an, lenc, nwl, icomm);

% Reconstruct without thresholding of detail coefficients
[b, ifail] = c09ed(nwl, c, m, n, icomm);
 
% Mean square error of noisy reconstruction
mse = (norm(reshape(a-b,[m*n,1]))^2)/(double(m*n));
fprintf('Without denoising Mean Square Error is %9.6f\n',mse);

% De-noise by applying hard threshold to detail coefficients
thresh = 0.01*sqrt(2*log(double(m*n)));
nt = 0;
nnt = 0;
for ilev = 1:nwl
  level = int64(nwl - ilev + 1);

  for detail = int64(1:3)
    % Extract the selected set of coefficients. 
    [d, icomm, ifail] = c09ey(...
                               level, detail, c, icomm);
  
    % Threshold
    d1 = dwtlvm(ilev);
    d2 = dwtlvn(ilev);
    for i = 1:d1
      for j = 1:d2
        if abs(d(i,j))<thresh
           d(i,j) = 0;
           nt = nt + 1;
        end
        nnt = nnt + 1;
      end
    end
    % Insert de-noised coefficients back into c
    [c, icomm, ifail] = c09ez(...
                               level, detail, c, d, icomm);
  end
end

fprintf('\nNumber of coefficients denoised is %3d out of %3d\n',nt,nnt);

% Reconstruct data after threholding
[b, ifail] = c09ed(nwl, c, m, n, icomm);

% Mean square error of de-noised reconstruction
mse = (norm(reshape(a-b,[m*n,1]))^2)/(double(m*n));
fprintf('With denoising Mean Square Error is %9.6f\n\n',mse);

disp('Reconstruction of denoised input: ');
disp(b);


c09ey example results


Input data a:
    0.0100    0.0100    0.0100    0.0100    0.0100    0.0100
    1.0000    1.0000    1.0000    1.0000    1.0000    1.0000
    0.0100    0.0100    0.0100    0.0100    0.0100    0.0100
    1.0000    1.0000    1.0000    1.0000    1.0000    1.0000
    0.0100    0.0100    0.0100    0.0100    0.0100    0.0100
    1.0000    1.0000    1.0000    1.0000    1.0000    1.0000
    0.0100    0.0100    0.0100    0.0100    0.0100    0.0100


Noisy data an:
    0.0135    0.0170   -0.0049   -0.0009    0.0002    0.0123
    1.0015    0.9896    0.9983    1.0044    1.0097    0.9847
   -0.0017    0.0107    0.0194   -0.0084    0.0114   -0.0006
    0.9899    1.0038    1.0005    0.9921    0.9923    0.9982
   -0.0093    0.0149    0.0094    0.0160    0.0058    0.0257
    0.9842    1.0278    0.9991    0.9956    1.0113    0.9911
    0.0139   -0.0011    0.0180    0.0187    0.0106    0.0118

Without denoising Mean Square Error is  0.000098

Number of coefficients denoised is  32 out of  48
With denoising Mean Square Error is  0.000018

Reconstruction of denoised input: 
    0.0127    0.0094    0.0030    0.0007    0.0009    0.0065
    0.9913    0.9940    1.0000    1.0027    1.0032    0.9976
    0.0084    0.0086    0.0072    0.0048    0.0028    0.0050
    1.0009    0.9998    0.9966    0.9942    0.9930    0.9965
    0.0061    0.0070    0.0103    0.0134    0.0154    0.0114
    1.0034    1.0036    1.0028    1.0011    0.9996    1.0011
    0.0135    0.0113    0.0093    0.0114    0.0147    0.0148


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015