# NAG CL Interfacec09fzc (dim3_​coeff_​ins)

## 1Purpose

c09fzc inserts a selected set of three-dimensional discrete wavelet transform (DWT) coefficients into the full set of coefficients stored in compact form, which may be later used as input to the reconstruction functions c09fbc or c09fdc.

## 2Specification

 #include
 void c09fzc (Integer ilev, Integer cindex, Integer lenc, double c[], const double d[], Integer ldd, Integer sdd, Integer icomm[], NagError *fail)
The function may be called by the names: c09fzc, nag_wav_dim3_coeff_ins or nag_wav_3d_coeff_ins.

## 3Description

c09fzc inserts a selected set of three-dimensional DWT coefficients into the full set of coefficients stored in compact form in a one-dimensional array c. It is required that c09fzc is preceded by a call to the initialization function c09acc and either the forwards transform function c09fac or multi-level forwards transform function c09fcc.
Given an initial three-dimensional data set $A$, a prior call to c09fac or c09fcc computes the approximation coefficients (at the highest requested level in the case of c09fcc) and, seven sets of detail coefficients (at all levels in the case of c09fcc) and stores these in compact form in a one-dimensional array c. c09fyc can then extract either the approximation coefficients or one of the sets of detail coefficients (at one of the levels following c09fcc) as three-dimensional data into the array, d. Following some calculation on this set of coefficients (for example, denoising), the updated coefficients in d are inserted back into the full set c using c09fzc. Several extractions and insertions may be performed. c09fbc or c09fdc can then be used to reconstruct a manipulated data set $\stackrel{~}{A}$. The dimensions of the three-dimensional data stored in d depend on the level extracted and are available from either: the arrays dwtlvm, dwtlvn and dwtlvfr as returned by c09fcc if this was called first; or, otherwise from nwct, nwcn and nwcfr as returned by c09acc. See Section 2.1 in the C09 Chapter Introduction for a discussion of the three-dimensional DWT.

None.

## 5Arguments

Note: the following notation is used in this section:
• ${n}_{\mathrm{cm}}$ is the number of wavelet coefficients in the first dimension. Following a call to c09fac (i.e., when ${\mathbf{ilev}}=0$) this is equal to ${\mathbf{nwct}}/\left(8×{\mathbf{nwcn}}×{\mathbf{nwcfr}}\right)$ as returned by c09acc. Following a call to c09fcc transforming nwl levels, and when inserting at level ${\mathbf{ilev}}>0$, this is equal to ${\mathbf{dwtlvm}}\left[{\mathbf{nwl}}-{\mathbf{ilev}}\right]$.
• ${n}_{\mathrm{cn}}$ is the number of wavelet coefficients in the second dimension. Following a call to c09fac (i.e., when ${\mathbf{ilev}}=0$) this is equal to nwcn as returned by c09acc. Following a call to c09fcc transforming nwl levels, and when inserting at level ${\mathbf{ilev}}>0$, this is equal to ${\mathbf{dwtlvn}}\left[{\mathbf{nwl}}-{\mathbf{ilev}}\right]$.
• ${n}_{\mathrm{cfr}}$ is the number of wavelet coefficients in the third dimension. Following a call to c09fac (i.e., when ${\mathbf{ilev}}=0$) this is equal to nwcfr as returned by c09acc. Following a call to c09fcc transforming nwl levels, and when inserting at level ${\mathbf{ilev}}>0$, this is equal to ${\mathbf{dwtlvfr}}\left[{\mathbf{nwl}}-{\mathbf{ilev}}\right]$
1: $\mathbf{ilev}$Integer Input
On entry: the level at which coefficients are to be inserted.
If ${\mathbf{ilev}}=0$, it is assumed that the coefficient array c was produced by a preceding call to the single level function c09fac.
If ${\mathbf{ilev}}>0$, it is assumed that the coefficient array c was produced by a preceding call to the multi-level function c09fcc.
Constraints:
• ${\mathbf{ilev}}=0$ (following a call to c09fac);
• $0\le {\mathbf{ilev}}\le {\mathbf{nwl}}$, where nwl is as used in a preceding call to c09fcc;
• if ${\mathbf{cindex}}=0$, ${\mathbf{ilev}}={\mathbf{nwl}}$ (following a call to c09fcc).
2: $\mathbf{cindex}$Integer Input
On entry: identifies which coefficients to insert. The coefficients are identified as follows:
${\mathbf{cindex}}=0$
The approximation coefficients, produced by application of the low pass filter over columns, rows and frames of $A$ (LLL). After a call to the multi-level transform function c09fcc (which implies that ${\mathbf{ilev}}>0$) the approximation coefficients are present only for ${\mathbf{ilev}}={\mathbf{nwl}}$, where nwl is the value used in a preceding call to c09fcc.
${\mathbf{cindex}}=1$
The detail coefficients produced by applying the low pass filter over columns and rows of $A$ and the high pass filter over frames (LLH).
${\mathbf{cindex}}=2$
The detail coefficients produced by applying the low pass filter over columns, high pass filter over rows and low pass filter over frames of $A$ (LHL).
${\mathbf{cindex}}=3$
The detail coefficients produced by applying the low pass filter over columns of $A$ and high pass filter over rows and frames (LHH).
${\mathbf{cindex}}=4$
The detail coefficients produced by applying the high pass filter over columns of $A$ and low pass filter over rows and frames (HLL).
${\mathbf{cindex}}=5$
The detail coefficients produced by applying the high pass filter over columns, low pass filter over rows and high pass filter over frames of $A$ (HLH).
${\mathbf{cindex}}=6$
The detail coefficients produced by applying the high pass filter over columns and rows of $A$ and the low pass filter over frames (HHL).
${\mathbf{cindex}}=7$
The detail coefficients produced by applying the high pass filter over columns, rows and frames of $A$ (HHH).
Constraints:
• if ${\mathbf{ilev}}=0$, $0\le {\mathbf{cindex}}\le 7$;
• if ${\mathbf{ilev}}={\mathbf{nwl}}$, following a call to c09fcc transforming nwl levels, $0\le {\mathbf{cindex}}\le 7$;
• otherwise $1\le {\mathbf{cindex}}\le 7$.
3: $\mathbf{lenc}$Integer Input
On entry: the dimension of the array c.
Constraint: lenc must be unchanged from the value used in the preceding call to either c09fac or c09fcc.
4: $\mathbf{c}\left[{\mathbf{lenc}}\right]$double Input/Output
On entry: contains the DWT coefficients inserted by previous calls to c09fzc, or computed by a previous call to either c09fac or c09fcc.
On exit: contains the same DWT coefficients provided on entry except for those identified by ilev and cindex, which are updated with the values supplied in d, inserted into the correct locations as expected by one of the reconstruction functions c09fbc (if c09fac was called previously) or c09fdc (if c09fcc was called previously).
5: $\mathbf{d}\left[\mathit{dim}\right]$const double Input
Note: the dimension, dim, of the array d must be at least ${\mathbf{ldd}}×{\mathbf{sdd}}×{n}_{\mathrm{cfr}}$.
On entry: the coefficients to be inserted.
If the DWT coefficients were computed by c09fac then
• if ${\mathbf{cindex}}=0$, the approximation coefficients must be stored in ${\mathbf{d}}\left[\left(\mathit{k}-1\right)×{\mathbf{ldd}}×{\mathbf{sdd}}+\left(\mathit{j}-1\right)×{\mathbf{ldd}}+i-1\right]$, for $\mathit{i}=1,2,\dots ,{n}_{\mathrm{cm}}$, $\mathit{j}=1,2,\dots ,{n}_{\mathrm{cn}}$ and $\mathit{k}=1,2,\dots ,{n}_{\mathrm{cfr}}$;
• if $1\le {\mathbf{cindex}}\le 7$, the detail coefficients, as indicated by cindex, must be stored in ${\mathbf{d}}\left[\left(\mathit{k}-1\right)×{\mathbf{ldd}}×{\mathbf{sdd}}+\left(\mathit{j}-1\right)×{\mathbf{ldd}}+i-1\right]$, for $\mathit{i}=1,2,\dots ,{n}_{\mathrm{cm}}$, $\mathit{j}=1,2,\dots ,{n}_{\mathrm{cn}}$ and $\mathit{k}=1,2,\dots ,{n}_{\mathrm{cfr}}$.
If the DWT coefficients were computed by c09fcc then
• if ${\mathbf{cindex}}=0$ and ${\mathbf{ilev}}={\mathbf{nwl}}$, the approximation coefficients must be stored in ${\mathbf{d}}\left[\left(\mathit{k}-1\right)×{\mathbf{ldd}}×{\mathbf{sdd}}+\left(\mathit{j}-1\right)×{\mathbf{ldd}}+i-1\right]$, for $\mathit{i}=1,2,\dots ,{n}_{\mathrm{cm}}$, $\mathit{j}=1,2,\dots ,{n}_{\mathrm{cn}}$ and $\mathit{k}=1,2,\dots ,{n}_{\mathrm{cfr}}$;
• if $1\le {\mathbf{cindex}}\le 7$, the detail coefficients, as indicated by cindex, for level ilev must be stored in ${\mathbf{d}}\left[\left(\mathit{k}-1\right)×{\mathbf{ldd}}×{\mathbf{sdd}}+\left(\mathit{j}-1\right)×{\mathbf{ldd}}+i-1\right]$, for $\mathit{i}=1,2,\dots ,{n}_{\mathrm{cm}}$, $\mathit{j}=1,2,\dots ,{n}_{\mathrm{cn}}$ and $\mathit{k}=1,2,\dots ,{n}_{\mathrm{cfr}}$.
6: $\mathbf{ldd}$Integer Input
On entry: the stride separating row elements of each of the sets of frame coefficients in the three-dimensional data stored in d.
Constraint: ${\mathbf{ldd}}>{n}_{\mathrm{cm}}$.
7: $\mathbf{sdd}$Integer Input
On entry: the stride separating corresponding coefficients of consecutive frames in the three-dimensional data stored in d.
Constraint: ${\mathbf{sdd}}>{n}_{\mathrm{cn}}$.
8: $\mathbf{icomm}\left[260\right]$Integer Communication Array
On entry: contains details of the discrete wavelet transform and the problem dimension as setup in the call to the initialization function c09acc.
9: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INITIALIZATION
Either the initialization function has not been called first or icomm has been corrupted.
NE_INT
On entry, ${\mathbf{cindex}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{cindex}}\le 7$.
On entry, ${\mathbf{cindex}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{cindex}}\ge 0$.
On entry, ${\mathbf{ilev}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ilev}}=0$ following a call to the single level function c09fac.
On entry, ${\mathbf{ilev}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ilev}}>0$ following a call to the multi-level function c09fcc.
NE_INT_2
On entry, ${\mathbf{ilev}}=〈\mathit{\text{value}}〉$ and ${\mathbf{nwl}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ilev}}\le {\mathbf{nwl}}$, where ${\mathbf{nwl}}$ is the number of levels used in the call to c09fcc.
On entry, ${\mathbf{ldd}}=〈\mathit{\text{value}}〉$ and ${n}_{\mathrm{cm}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldd}}\ge {n}_{\mathrm{cm}}$, where ${n}_{\mathrm{cm}}$ is the number of DWT coefficients in the first dimension following the single level transform.
On entry, ${\mathbf{lenc}}=〈\mathit{\text{value}}〉$ and ${n}_{\mathrm{ct}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lenc}}\ge {n}_{\mathrm{ct}}$, where ${n}_{\mathrm{ct}}$ is the number of DWT coefficients computed in a previous call to c09fac.
On entry, ${\mathbf{lenc}}=〈\mathit{\text{value}}〉$ and ${n}_{\mathrm{ct}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lenc}}\ge {n}_{\mathrm{ct}}$, where ${n}_{\mathrm{ct}}$ is the number of DWT coefficients computed in a previous call to c09fcc.
On entry, ${\mathbf{sdd}}=〈\mathit{\text{value}}〉$ and ${n}_{\mathrm{cn}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{sdd}}\ge {n}_{\mathrm{cn}}$, where ${n}_{\mathrm{cn}}$ is the number of DWT coefficients in the second dimension following the single level transform.
NE_INT_3
On entry, ${\mathbf{ilev}}=〈\mathit{\text{value}}〉$ and ${\mathbf{nwl}}=〈\mathit{\text{value}}〉$, but ${\mathbf{cindex}}=0$.
Constraint: ${\mathbf{cindex}}>0$ when ${\mathbf{ilev}}<{\mathbf{nwl}}$ in the preceding call to c09fcc.
On entry, ${\mathbf{ldd}}=〈\mathit{\text{value}}〉$ and ${n}_{\mathrm{cm}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldd}}\ge {n}_{\mathrm{cm}}$, where ${n}_{\mathrm{cm}}$ is the number of DWT coefficients in the first dimension at the selected level ilev.
On entry, ${\mathbf{sdd}}=〈\mathit{\text{value}}〉$ and ${n}_{\mathrm{cn}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{sdd}}\ge {n}_{\mathrm{cn}}$, where ${n}_{\mathrm{cn}}$ is the number of DWT coefficients in the second dimension at the selected level ilev.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.

Not applicable.

## 8Parallelism and Performance

c09fzc is not threaded in any implementation.

None.

## 10Example

The following example demonstrates using the coefficient extraction and insertion functions in order to apply denoising using a thresholding operation. The original input data has artificial noise introduced to it, taken from a normal random number distribution. Reconstruction then takes place on both the noisy data and denoised data. The Mean Square Errors (MSE) of the two reconstructions are printed along with the reconstruction of the denoised data. The MSE of the denoised reconstruction is less than that of the noisy reconstruction.

### 10.1Program Text

Program Text (c09fzce.c)

### 10.2Program Data

Program Data (c09fzce.d)

### 10.3Program Results

Program Results (c09fzce.r)