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_3d_multi_fwd (c09fc)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_wav_3d_multi_fwd (c09fc) computes the three-dimensional multi-level discrete wavelet transform (DWT). The initialization function nag_wav_3d_init (c09ac) must be called first to set up the DWT options.

Syntax

[c, dwtlvm, dwtlvn, dwtlvfr, icomm, ifail] = c09fc(n, fr, a, lenc, nwl, icomm, 'm', m)
[c, dwtlvm, dwtlvn, dwtlvfr, icomm, ifail] = nag_wav_3d_multi_fwd(n, fr, a, lenc, nwl, icomm, 'm', m)

Description

nag_wav_3d_multi_fwd (c09fc) computes the multi-level DWT of three-dimensional data. For a given wavelet and end extension method, nag_wav_3d_multi_fwd (c09fc) will compute a multi-level transform of a three-dimensional array A, using a specified number, nfwd, of levels. The number of levels specified, nfwd, must be no more than the value lmax returned in nwlmax by the initialization function nag_wav_3d_init (c09ac) for the given problem. The transform is returned as a set of coefficients for the different levels (packed into a single array) and a representation of the multi-level structure.
The notation used here assigns level 0 to the input data, A. Level 1 consists of the first set of coefficients computed: the seven sets of detail coefficients are stored at this level while the approximation coefficients are used as the input to a repeat of the wavelet transform at the next level. This process is continued until, at level nfwd, all eight types of coefficients are stored. All coefficients are packed into a single array.

References

Wang Y, Che X and Ma S (2012) Nonlinear filtering based on 3D wavelet transform for MRI denoising URASIP Journal on Advances in Signal Processing 2012:40

Parameters

Compulsory Input Parameters

1:     n int64int32nag_int scalar
The number of columns of each two-dimensional frame.
Constraint: this must be the same as the value n passed to the initialization function nag_wav_3d_init (c09ac).
2:     fr int64int32nag_int scalar
The number of two-dimensional frames.
Constraint: this must be the same as the value fr passed to the initialization function nag_wav_3d_init (c09ac).
3:     aldasdafr – double array
lda, the first dimension of the array, must satisfy the constraint ldam.
The m by n by fr three-dimensional input data A, where with Aijk stored in aijk.
4:     lenc int64int32nag_int scalar
The dimension of the array c.
Constraint: lencnct, where nct is the total number of wavelet coefficients that correspond to a transform with nwl levels.
5:     nwl int64int32nag_int scalar
The number of levels, nfwd, in the multi-level resolution to be performed.
Constraint: 1nwllmax, where lmax is the value returned in nwlmax (the maximum number of levels) by the call to the initialization function nag_wav_3d_init (c09ac).
6:     icomm260 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_3d_init (c09ac).

Optional Input Parameters

1:     m int64int32nag_int scalar
Default: the first dimension of the array a.
The number of rows of each two-dimensional frame.
Constraint: this must be the same as the value m passed to the initialization function nag_wav_3d_init (c09ac).

Output Parameters

1:     clenc – double array
The coefficients of the discrete wavelet transform. If you need to access or modify the approximation coefficients or any specific set of detail coefficients then the use of nag_wav_3d_coeff_ext (c09fy) or nag_wav_3d_coeff_ins (c09fz) is recommended. For completeness the following description provides details of precisely how the coefficients are stored in c but this information should only be required in rare cases.
Let qi denote the number of coefficients of each type at level i, for i=1,2,,nfwd, such that qi= dwtlvmnfwd-i+1× dwtlvnnfwd-i+1× dwtlvfrnfwd-i+1 . Then, letting k1=qnfwd and kj+1=kj+qnfwd-j/7+1, for j=1,2,,7nfwd, the coefficients are stored in c as follows:
ci, for i=1,2,,k1
Contains the level nfwd approximation coefficients, anfwd. Note that for computational efficiency reasons these coefficients are stored as dwtlvm1× dwtlvn1× dwtlvfr1 in c.
ci, for i=kj+1,,kj+1
Contains the level nfwd-j/7+1 detail coefficients. These are:
  • LLH coefficients if j mod 7=1;
  • LHL coefficients if j mod 7=2;
  • LHH coefficients if j mod 7=3;
  • HLL coefficients if j mod 7=4;
  • HLH coefficients if j mod 7=5;
  • HHL coefficients if j mod 7=6;
  • HHH coefficients if j mod 7=0,
for j=1,,7nfwd. See Multiresolution and higher dimensional DWT in the C09 Chapter Introduction for a description of how these coefficients are produced.
Note that for computational efficiency reasons these coefficients are stored as dwtlvfr j/7 × dwtlvm j/7 × dwtlvn j/7 in c.
2:     dwtlvmnwl int64int32nag_int array
The number of coefficients in the first dimension for each coefficient type at each level. dwtlvmi contains the number of coefficients in the first dimension (for each coefficient type computed) at the (nfwd-i+1)th level of resolution, for i=1,2,,nfwd.
3:     dwtlvnnwl int64int32nag_int array
The number of coefficients in the second dimension for each coefficient type at each level. dwtlvni contains the number of coefficients in the second dimension (for each coefficient type computed) at the (nfwd-i+1)th level of resolution, for i=1,2,,nfwd.
4:     dwtlvfrnwl int64int32nag_int array
The number of coefficients in the third dimension for each coefficient type at each level. dwtlvfri contains the number of coefficients in the third dimension (for each coefficient type computed) at the (nfwd-i+1)th level of resolution, for i=1,2,,nfwd.
5:     icomm260 int64int32nag_int array
Contains additional information on the computed transform.
6:     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: fr=_, the value of fr on initialization (see nag_wav_3d_init (c09ac)).
Constraint: m=_, the value of m on initialization (see nag_wav_3d_init (c09ac)).
Constraint: n=_, the value of n on initialization (see nag_wav_3d_init (c09ac)).
   ifail=2
Constraint: ldam.
Constraint: sdan.
   ifail=3
lenc is too small, the total number of coefficents to be generated.
   ifail=5
Constraint: nwlnwlmax in nag_wav_3d_init (c09ac).
Constraint: nwl1.
   ifail=6
Either the communication array icomm has been corrupted or there has not been a prior call to the initialization function nag_wav_3d_init (c09ac).
The initialization function was called with wtrans='S'.
   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

The accuracy of the wavelet transform depends only on the floating-point operations used in the convolution and downsampling and should thus be close to machine precision.

Further Comments

The example program shows how the wavelet coefficients at each level can be extracted from the output array c. Denoising can be carried out by applying a thresholding operation to the detail coefficients at every level. If cij is a detail coefficient then c^ij=cij+σεij and σεij is the transformed noise term. If some threshold parameter α is chosen, a simple hard thresholding rule can be applied as
c- ij = 0, if ​ c^ij α c^ij , if ​ c^ij > α,  
taking c-ij to be an approximation to the required detail coefficient without noise, cij. The resulting coefficients can then be used as input to nag_wav_3d_mxolap_multi_inv (c09fd) in order to reconstruct the denoised signal. See Example in nag_wav_3d_coeff_ins (c09fz) for a simple example of denoising.
See the references given in the introduction to this chapter for a more complete account of wavelet denoising and other applications.

Example

This example computes the three-dimensional multi-level discrete wavelet decomposition for 7×6×5 input data using the biorthogonal wavelet of order 1.1 (set wavnam='BIOR1.1' in nag_wav_3d_init (c09ac)) with periodic end extension, prints a selected set of wavelet coefficients and then reconstructs and verifies that the reconstruction matches the original data.
function c09fc_example


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

% Data
m  = int64(7);
n  = int64(6);
fr = int64(5);
a = zeros(m, n, fr);
a(:, :, 1) = [3, 2, 2, 2, 1, 1;
              2, 9, 1, 2, 1, 3;
              2, 5, 1, 2, 1, 1;
              1, 6, 2, 2, 7, 2;
              5, 3, 2, 2, 4, 7;
              2, 2, 1, 1, 2, 1;
              6, 2, 1, 3, 6, 9];
a(:, :, 2) = [2, 1, 5, 1, 2, 3;
              2, 9, 5, 2, 1, 2;
              2, 3, 2, 7, 1, 1;
              2, 1, 1, 2, 3, 1;
              2, 1, 2, 8, 3, 3;
              1, 4, 5, 1, 2, 7;
              8, 1, 3, 9, 1, 2];
a(:, :, 3) = [3, 1, 4, 1, 1, 1;
              1, 1, 2, 1, 2, 6;
              4, 1, 7, 2, 5, 6;
              3, 2, 1, 5, 9, 5;
              1, 1, 2, 2, 2, 1;
              2, 6, 3, 9, 5, 1;
              1, 1, 8, 2, 1, 3];
a(:, :, 4) = [5, 8, 1, 2, 2, 1;
              1, 2, 2, 9, 2, 9;
              2, 2, 2, 1, 1, 3;
              1, 1, 1, 5, 1, 2;
              3, 2, 8, 1, 9, 2;
              2, 1, 9, 1, 2, 2;
              3, 6, 5, 3, 2, 2];
a(:, :, 5) = [5, 2, 1, 2, 1, 1;
              3, 1, 9, 1, 2, 1;
              2, 3, 1, 1, 7, 2;
              7, 2, 2, 6, 1, 1;
              5, 1, 7, 2, 1, 1;
              2, 1, 3, 2, 2, 1;
              5, 3, 9, 1, 4, 1];

% Query wavelet filter dimensions
wavnam = 'Bior1.1';
mode   = 'period';
wtrans = 'Multilevel';
[nwl, nf, nwct, nwcn, nwcfr, icomm, ifail] = ...
  c09ac(...
         wavnam, wtrans, mode, m, n, fr);

% Perform Discrete Wavelet transform
[c, dwtlvm, dwtlvn, dwtlvfr, icomm, ifail] = ...
  c09fc(...
         n, fr, a, nwct, nwl, icomm);

fprintf(' Number of Levels : %d\n\n', nwl);
fprintf(' Number of coefficients in 1st dimension for each level:\n');
fprintf(' %8d', dwtlvm(1:nwl));
fprintf('\n');
fprintf(' Number of coefficients in 2nd dimension for each level:\n');
fprintf(' %8d', dwtlvn(1:nwl));
fprintf('\n');
fprintf(' Number of coefficients in 3rd dimension for each level:\n');
fprintf(' %8d', dwtlvfr(1:nwl));
fprintf('\n');

% Print the first level HLL detail coefficients
want_level = int64(1);
want_coeffs = int64(4);

cpass = char('LLH','LHL','LHH','HLL','HLH','HHL','HHH');

if (want_coeffs==0) 
  title = 'Approximation coefficients (LLL)'
else
  title = sprintf('Detail coefficients (%s)',cpass(want_coeffs,:));
end

% Extract coefficients
[d, icomm, ifail] = c09fy(...
                           want_level, want_coeffs, c, icomm);
fprintf('\n%s\n Level %2d, Coefficients %2d :\n',title, want_level, ...
        want_coeffs );

% Matrix printing arguments
matrix = 'General'; diag   = 'Non-unit'; fmt = 'F9.4';
labrow = 'Integer'; labcol = labrow;
rlabs  = {' '};     clabs  = rlabs;
ncols  = int64(80); indent = int64(0);

nk = dwtlvfr(nwl-want_level+1);
for k = 1:nk
  title = sprintf('Frame: %3d',k);
  [ifail] =  x04cb(...
                    matrix, diag, d(:,:,k), fmt, title, labrow, ...
                   rlabs, labcol, clabs, ncols, indent);
end
 
% Reconstruct original data
[b, ifail] = c09fd(nwl, c, m, n, fr, icomm);

% Check reconstruction matches original
eps = 10*double(m*n*fr)*x02aj;
err = a-b;
frob = 0;
for i=1:fr
  fnew = sqrt(sum(sum(err(:,:,i).^2)));
  frob = max(frob,fnew);
end

if frob < eps
  fprintf('\nSuccess: the reconstruction matches the original.\n');
else
  fprintf('\nFail: Frobenius norm of b-a is too large.\n');
end


c09fc example results

 Number of Levels : 2

 Number of coefficients in 1st dimension for each level:
        2        4
 Number of coefficients in 2nd dimension for each level:
        2        3
 Number of coefficients in 3rd dimension for each level:
        2        3

Detail coefficients (HLL)
 Level  1, Coefficients  4 :
 Frame:   1
           1        2        3
 1   -4.9497   0.0000   0.0000
 2    0.7071   1.7678  -3.1820
 3    0.7071   2.1213   1.7678
 4    0.0000   0.0000   0.0000
 Frame:   2
           1        2        3
 1    4.2426  -2.1213  -4.9497
 2    0.7071  -0.0000  -0.7071
 3   -1.4142  -3.1820   1.4142
 4    0.0000   0.0000   0.0000
 Frame:   3
           1        2        3
 1    2.1213  -4.9497  -0.7071
 2   -2.8284  -4.2426   4.9497
 3    2.1213   2.8284  -0.7071
 4    0.0000   0.0000   0.0000

Success: the reconstruction matches the original.

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