 DWT2D - Maple Help

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, 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.
 • 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

 > $\mathrm{with}\left(\mathrm{ImageTools}\right):$
 > $\mathrm{img}≔\mathrm{Read}\left(\mathrm{cat}\left(\mathrm{kernelopts}\left(\mathrm{datadir}\right),"/images/ship.jpg"\right)\right)$
 ${{\mathrm{_rtable}}}_{{36893628738149056748}}$ (5.1)
 > $\mathrm{Embed}\left(\mathrm{img}\right)$ > $\mathrm{result}≔\mathrm{DWT2D}\left(\mathrm{img},'\mathrm{level}'=1\right):$

The Embed command needs its images to have datatype float. The DWT2D command returns its results with datatype float.

 > $\mathrm{result8}≔\mathrm{map}\left(\mathrm{rtable},\mathrm{result},\mathrm{datatype}=\mathrm{float}\left[8\right]\right):$
 > $\mathrm{Embed}\left(\left[\left[\mathrm{result8}\left[1\right],\mathrm{result8}\left[2\right]\right],\left[\mathrm{result8}\left[3\right],\mathrm{result8}\left[4\right]\right]\right]\right)$    > $\mathrm{invresult}≔\mathrm{InverseDWT2D}\left(\mathrm{result}\right)$
 ${{\mathrm{_rtable}}}_{{36893628738039212620}}$ (5.2)
 > $\mathrm{Embed}\left(\mathrm{invresult}\right)$
 > $A≔\mathrm{Array}\left(1..3,1..3,\left(i,j\right)↦j+3\cdot i-3\right)$
 $\left[\begin{array}{rrr}1& 2& 3\\ 4& 5& 6\\ 7& 8& 9\end{array}\right]$ (5.3)
 > $\mathrm{result2}≔\mathrm{DWT2D}\left(A,'\mathrm{bordermode}'='\mathrm{const}','\mathrm{bordervalue}'=25,'\mathrm{output}'='\mathrm{threelists}'\right)$
 $\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)
 > $\mathrm{InverseDWT2D}\left(\mathrm{result2}\right)$
 $\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.