Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_wav_3d_sngl_inv (c09fb)

## Purpose

nag_wav_3d_sngl_inv (c09fb) computes the three-dimensional inverse discrete wavelet transform (IDWT) at a single level. The initialization function nag_wav_3d_init (c09ac) must be called first to set up the DWT options.

## Syntax

[b, ifail] = c09fb(m, n, fr, c, icomm, 'lenc', lenc)
[b, ifail] = nag_wav_3d_sngl_inv(m, n, fr, c, icomm, 'lenc', lenc)

## Description

nag_wav_3d_sngl_inv (c09fb) performs the inverse operation of function nag_wav_3d_sngl_fwd (c09fa). That is, given sets of wavelet coefficients computed by function nag_wav_3d_sngl_fwd (c09fa) using a DWT as set up by the initialization function nag_wav_3d_init (c09ac), on a real data array, $B$, nag_wav_3d_sngl_inv (c09fb) will reconstruct $B$.

None.

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{m}$int64int32nag_int scalar
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).
2:     $\mathrm{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).
3:     $\mathrm{fr}$int64int32nag_int scalar
The number two-dimensional frames.
Constraint: this must be the same as the value fr passed to the initialization function nag_wav_3d_init (c09ac).
4:     $\mathrm{c}\left({\mathbf{lenc}}\right)$ – double array
The coefficients of the discrete wavelet transform. This will normally be the result of some transformation on the coefficients computed by function nag_wav_3d_sngl_fwd (c09fa).
Note that the coefficients in c may be extracted according to type into three-dimensional arrays using nag_wav_3d_coeff_ext (c09fy), and inserted using nag_wav_3d_coeff_ins (c09fz).
5:     $\mathrm{icomm}\left(260\right)$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:     $\mathrm{lenc}$int64int32nag_int scalar
Default: the dimension of the array c.
The dimension of the array c.
Constraint: ${\mathbf{lenc}}\ge {n}_{\mathrm{ct}}$, where ${n}_{\mathrm{ct}}$ is the total number of wavelet coefficients, as returned by nag_wav_3d_init (c09ac).

### Output Parameters

1:     $\mathrm{b}\left(\mathit{ldb},\mathit{sdb},{\mathbf{fr}}\right)$ – double array
$\mathit{sdb}={\mathbf{n}}$.
The $m$ by $n$ by $\mathit{fr}$ reconstructed array, $B$, with ${B}_{ijk}$ stored in ${\mathbf{b}}\left(i,j,k\right)$. The reconstruction is based on the input wavelet coefficients and the transform options supplied to the initialization function nag_wav_3d_init (c09ac).
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
Constraint: ${\mathbf{fr}}=_$, the value of fr on initialization (see nag_wav_3d_init (c09ac)).
Constraint: ${\mathbf{m}}=_$, the value of m on initialization (see nag_wav_3d_init (c09ac)).
Constraint: ${\mathbf{n}}=_$, the value of n on initialization (see nag_wav_3d_init (c09ac)).
${\mathbf{ifail}}=2$
Constraint: $\mathit{ldb}\ge {\mathbf{m}}$.
Constraint: $\mathit{sdb}\ge {\mathbf{n}}$.
${\mathbf{ifail}}=3$
Constraint: ${\mathbf{lenc}}\ge {n}_{\mathrm{ct}}$, where ${n}_{\mathrm{ct}}$ is the number of DWT coefficients returned by nag_wav_3d_init (c09ac) in argument nwct.
${\mathbf{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 ${\mathbf{wtrans}}=\text{'M'}$.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{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.

None.

## Example

See Example in nag_wav_3d_sngl_fwd (c09fa).
```function c09fb_example

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

m  = int64(5);
n  = int64(4);
fr = int64(3);
wavnam = 'Haar';
mode = 'half';
wtrans = 'Single Level';
a = zeros(m, n, fr);
a(:, :, 1) = [3, 2, 2, 2;
2, 9, 1, 2;
2, 5, 1, 2;
1, 6, 2, 2;
5, 3, 2, 2];
a(:, :, 2) = [2, 1, 5, 1;
2, 9, 5, 2;
2, 3, 2, 7;
2, 1, 1, 2;
2, 1, 2, 8];
a(:, :, 3) = [3, 1, 4, 1;
1, 1, 2, 1;
4, 1, 7, 2;
3, 2, 1, 5;
1, 1, 2, 2];

% Query wavelet filter dimensions
[lmax, nf, nwct, nwcn, nwcfr, icomm, ifail] = ...
c09ac(wavnam, wtrans, mode, m, n, fr);

nwcm = nwct/(8*nwcn*nwcfr);

% 3D DWT decomposition
[c, icomm, ifail] = c09fa(n, fr, a, nwct, icomm);

d = zeros(nwcm, nwcn, nwcfr);

for cindex = 0:7

% Decide which coefficient type we are considering and advance the
% pointer locc to the first element of that 3D array in C.
switch (cindex)
case {0}
fprintf('Approximation coefficients (LLL)\n');
locc = 1;
case {1}
fprintf('Detail coefficients (LLH)\n');
% Advance pointer past approximation coefficients
locc = nwcm*nwcn*nwcfr + 1;
case {2}
fprintf('Detail coefficients (LHL)\n');
% Advance pointer past approximation coefficients and 1 set of
% detail coefficients
locc = 2*nwcm*nwcn*nwcfr + 1;
case {3}
fprintf('Detail coefficients (LHH)\n');
% Advance pointer past approximation coefficients and 2 sets of
% detail coefficients
locc = 3*nwcm*nwcn*nwcfr + 1;
case {4}
fprintf('Detail coefficients (HLL)\n');
% Advance pointer past approximation coefficients and 3 sets of
% detail coefficients
locc = 4*nwcm*nwcn*nwcfr + 1;
case {5}
fprintf('Detail coefficients (HLH)\n');
% Advance pointer past approximation coefficients and 4 sets of
% detail coefficients
locc = 5*nwcm*nwcn*nwcfr + 1;
case {6}
fprintf('Detail coefficients (HHL)\n');
% Advance pointer past approximation coefficients and 5 sets of
% detail coefficients
locc = 6*nwcm*nwcn*nwcfr + 1;
case {7}
fprintf('Detail coefficients (HHH)\n');
% Advance pointer past approximation coefficients and 6 sets of
% detail coefficients
locc = 7*nwcm*nwcn*nwcfr + 1;
end

for k = 1:nwcfr
for j = 1:nwcn
for i = 1:nwcm
i1 = locc - 1 + (j-1)*nwcfr*nwcm + (i-1)*nwcfr + k;
d(i,j,k) = c(i1);
end
end
end

for j = 1:nwcfr
if (j==1)
fprintf('Coefficients        Frame 1');
else
fprintf('          Frame %d', j);
end
end
fprintf('\n');
d2 = reshape(d, nwcm, nwcn*nwcfr);
for i = 1:nwcm
if i == 1
fprintf('    %d         ', cindex);
else
fprintf('              ');
end
for j=1:nwcn*nwcfr
fprintf('%8.4f ', d2(i,j));
end
fprintf('\n');
end
end

% 3D DWT reconstruction
[b, ifail] = c09fb(m, n, fr, c, icomm);

fprintf('\nOutput Data          b : \n');
% Convert to int16 to get more compact output
for i=1:nwcm
fprintf('Frame %d :\n', i);
disp(b(:, :, i));
end

```
```c09fb example results

Approximation coefficients (LLL)
Coefficients        Frame 1          Frame 2
0          10.6066   7.0711   4.2426   5.6569
7.7782   6.7175   7.0711  10.6066
7.7782   9.8995   2.8284   5.6569
Detail coefficients (LLH)
Coefficients        Frame 1          Frame 2
1           0.7071  -2.1213   0.0000   0.0000
2.1213  -1.7678   0.0000   0.0000
3.5355  -4.2426   0.0000   0.0000
Detail coefficients (LHL)
Coefficients        Frame 1          Frame 2
2          -4.2426   2.1213   1.4142   2.8284
-2.8284  -2.4749   2.8284   0.7071
2.1213  -4.2426   0.0000   0.0000
Detail coefficients (LHH)
Coefficients        Frame 1          Frame 2
3           0.0000  -2.8284   0.0000   0.0000
-2.8284   1.7678   0.0000   0.0000
0.7071   4.2426   0.0000   0.0000
Detail coefficients (HLL)
Coefficients        Frame 1          Frame 2
4          -4.9497   0.0000   1.4142   1.4142
0.7071   1.7678  -0.0000   2.1213
0.0000   0.0000   0.0000   0.0000
Detail coefficients (HLH)
Coefficients        Frame 1          Frame 2
5           0.7071   0.7071   0.0000   0.0000
-0.7071  -2.4749   0.0000   0.0000
0.0000   0.0000   0.0000   0.0000
Detail coefficients (HHL)
Coefficients        Frame 1          Frame 2
6           5.6569   0.7071   1.4142   1.4142
0.0000  -1.7678   1.4142   6.3640
0.0000   0.0000   0.0000   0.0000
Detail coefficients (HHH)
Coefficients        Frame 1          Frame 2
7           0.0000   0.0000   0.0000   0.0000
1.4142   1.0607   0.0000   0.0000
0.0000   0.0000   0.0000   0.0000

Output Data          b :
Frame 1 :
3.0000    2.0000    2.0000    2.0000
2.0000    9.0000    1.0000    2.0000
2.0000    5.0000    1.0000    2.0000
1.0000    6.0000    2.0000    2.0000
5.0000    3.0000    2.0000    2.0000

Frame 2 :
2.0000    1.0000    5.0000    1.0000
2.0000    9.0000    5.0000    2.0000
2.0000    3.0000    2.0000    7.0000
2.0000    1.0000    1.0000    2.0000
2.0000    1.0000    2.0000    8.0000

Frame 3 :
3.0000    1.0000    4.0000    1.0000
1.0000    1.0000    2.0000    1.0000
4.0000    1.0000    7.0000    2.0000
3.0000    2.0000    1.0000    5.0000
1.0000    1.0000    2.0000    2.0000

```