ImageTools - Maple Programming Help

Home : Support : Online Help : Programming : ImageTools Package : ImageTools/DWT2D

ImageTools

 DWT2D
 compute forward discrete wavelet transform
 InverseDWT2D
 compute inverse discrete wavelet transform

 Calling Sequence DWT2D(img) InverseDWT2D(coefficients)

Parameters

 img - Image coefficients - list

Options

 • level : posint
 • bordermode : identical( repl, mirror, const, "repl", "mirror", "const" )
 • bordervalue : algebraic or list
 • output identical( listtriples, threelists, flat, default, "listtriples", "threelists", "flat", "default" )

Description

 • The DWT2D(img) command computes the Haar discrete wavelet transform of the image img. Where img can only be two dimensional or three dimensional. The low-pass decimation filter and the high-pass decimation filter used in this command are $\left[\frac{1}{2},\frac{1}{2}\right]$ and $\left[-\frac{1}{2},\frac{1}{2}\right]$.
 • The level option specifies the number of levels the wavelet transform should apply. At each level, discrete wavelet transform would be applied to Approximation. The default value is the maximum level. The maximum level can be specified as $\mathrm{ilog2}\left(\mathrm{min}\left(\mathrm{upperbound}\left(\mathrm{Approximation},1\right),\mathrm{upperbound}\left(\mathrm{Approximation},2\right)\right)\right)$.
 • When the wavelet transform is applied for one level, the command returns four Arrays with datatype float[4], denoted by Approximation, HorizontalDetail, VerticalDetail and DiagonalDetail. They are obtained by convolving by low-pass filters and high-pass filters. The relevant convolution process are listed below.

 Approximation convolve by low-pass filter horizontally and low-pass filter vertically HorizontalDetail convolve by low-pass filter horizontally and high-pass filter vertically VerticalDetail convolve by high-pass filter horizontally and low-pass filter vertically DiagonalDetail convolve by high-pass filter horizontally and high-pass filer vertically

 • The bordermode and bordervalue options are used to specify the border extension mode. The bordervalue option can only be specified when the bordermode option is set to const. The bordervalue option can be anything that can be converted to a float or a list of three elements that can be converted to floats, if the img parameter is three dimensional. If only one value is provided when img is three dimensional, this value will be used at each layer. There are three border modes that can be specified: repl, mirror and const. Let A be $\left[\begin{array}{ccccc}1& 2& 3& 4& 5\\ 6& 7& 8& 9& 10\\ 11& 12& 13& 14& 15\\ 16& 17& 18& 19& 20\end{array}\right]$. The resulting matrices of each border extension mode are shown below.
 • repl : $\left[\begin{array}{ccccccc}1& 1& 2& 3& 4& 5& 5\\ 1& 1& 2& 3& 4& 5& 5\\ 6& 6& 7& 8& 9& 10& 10\\ 11& 11& 12& 13& 14& 15& 15\\ 16& 16& 17& 18& 19& 20& 20\\ 16& 16& 17& 18& 19& 20& 20\end{array}\right]$
 • mirror : $\left[\begin{array}{ccccccc}7& 6& 7& 8& 9& 10& 9\\ 2& 1& 2& 3& 4& 5& 4\\ 7& 6& 7& 8& 9& 10& 9\\ 12& 11& 12& 13& 14& 15& 14\\ 17& 16& 17& 18& 19& 20& 19\\ 12& 11& 12& 13& 14& 15& 14\end{array}\right]$.
 • const with bordervalue = v : $\left[\begin{array}{ccccccc}v& v& v& v& v& v& v\\ v& 1& 2& 3& 4& 5& v\\ v& 6& 7& 8& 9& 10& v\\ v& 11& 12& 13& 14& 15& v\\ v& 16& 17& 18& 19& 20& v\\ v& v& v& v& v& v& v\end{array}\right]$.
 • The border extension is also used when the number of rows or columns of img are odd. In this case, an extra row or column would be added to extend the img, so that it has even number of rows and columns. The way to extend the columns or rows are specified by bordermode and bordervalue.
 • If output is specified to listtriples, then the command would return $\left[{\mathrm{Approximation}}_{\mathrm{level}},\left[{\mathrm{HorizontalDetail}}_{\mathrm{level}},{\mathrm{VerticalDetail}}_{\mathrm{level}},{\mathrm{DiagonalDetail}}_{\mathrm{level}}\right],..,\left[{\mathrm{HorizontalDetail}}_{1},{\mathrm{VerticalDetail}}_{1},{\mathrm{DiagonalDetail}}_{1}\right]\right]$. If output is specified to threelists, then the command would return $\left[{\mathrm{Approximation}}_{\mathrm{level}},\left[{\mathrm{HorizontalDetail}}_{\mathrm{level}},..,{\mathrm{HorizontalDetail}}_{1}\right],\left[{\mathrm{VerticalDetail}}_{\mathrm{level}},..,{\mathrm{VerticalDetail}}_{1}\right],\left[{\mathrm{DiagonalDetail}}_{\mathrm{level}},..,{\mathrm{DiagonalDetail}}_{1}\right]\right]$. If output is specified to flat, then the command would return $\left[{\mathrm{Approxiation}}_{\mathrm{level}},{\mathrm{HorizontalDetail}}_{\mathrm{level}},{\mathrm{VerticalDetail}}_{\mathrm{level}},{\mathrm{DiagonalDetail}}_{\mathrm{level}},..,{\mathrm{HorizontalDetail}}_{1},{\mathrm{VerticalDetail}}_{1},{\mathrm{DiagonalDetail}}_{1}\right]$. The default value for output is default which sets output to flat if level is one and sets output to listtriples when level is more than one.
 • The InverseDWT2D(coefficients) computes the inverse Haar discrete wavelet transform. The low-pass decimation filter and the high-pass decimation filter used in this command are $\left[1,1\right]$ and $\left[-1,1\right]$. It returns the results in an Array with datatype float[4].
 • The InverseDWT2D(coefficients) is not a perfect inverse if the expected output has odd number of rows or columns. Then, the output array would contains the extra row or column that is added in the internal DWT2D procedure. The bordermode and bordervalue must be the same as the input when applying DWT2D. The number of maximum level it can be specified depends on coefficients. The default level is the maximum levels the inverse can apply with the given coefficients. There is no output option in the InverseDWT2D command, but coefficients can be in any form that DWT2D returns.

Examples

 > with(ImageTools):
 ${{\mathrm{_rtable}}}_{{18446884225106120822}}$ (5.1)
 > Embed(img);

 > result := DWT2D(img, 'level' = 1):

The Embed command needs its images to have datatype float[8]. The DWT2D command returns its results with datatype float[4].

 > result8 := map(rtable, result, datatype = float[8]):
 > Embed([[result8[1], result8[2]], [result8[3], result8[4]]]);

 > invresult := InverseDWT2D(result);
 ${{\mathrm{_rtable}}}_{{18446884224993392630}}$ (5.2)
 > Embed(invresult);
 > A := Array(1..3, 1..3, (i,j) -> j + 3 * (i - 1));
 $\left[\begin{array}{rrr}1& 2& 3\\ 4& 5& 6\\ 7& 8& 9\end{array}\right]$ (5.3)
 > result2 := DWT2D(A, 'bordermode' = 'const', 'bordervalue' = 25, 'output' = 'threelists');
 $\left[\left[\begin{array}{cc}3.0& 14.75\\ 16.25& 21.0\end{array}\right]{,}\left[\left[\begin{array}{cc}1.5& 0.75\\ 8.75& 4.0\end{array}\right]\right]{,}\left[\left[\begin{array}{cc}0.5& 10.25\\ 0.25& 4.0\end{array}\right]\right]{,}\left[\left[\begin{array}{cc}0.0& -0.75\\ -0.25& -4.0\end{array}\right]\right]\right]$ (5.4)
 > InverseDWT2D(result2);
 $\left[\begin{array}{cccc}1.0& 2.0& 3.0& 25.0\\ 4.0& 5.0& 6.0& 25.0\\ 7.0& 8.0& 9.0& 25.0\\ 25.0& 25.0& 25.0& 25.0\end{array}\right]$ (5.5)
 >

Compatibility

 • The ImageTools[DWT2D] and ImageTools[InverseDWT2D] commands were introduced in Maple 2020.