My problem is pretty basic but fundamental. It relates to the way discrete wavelet transform behaves for biorothognal 4.4 or CDF wavelets. When using most wavelets (e.g., CDF 9/7 or bio4.4 or Daubechies higher order wavelets) the size of the returned approximation and detail matrices is not a power of two. For my application (Embedded Zero Tree compression), this presents a problem because I want to construct a quad tree decomposition of the transformed image which requires all decompositions (LL, LH, HL and HH) to be of size a power of two. For example, consider the Mathematica code:

data = RandomReal[{0, 1}, {16, 16}];
dwd = DiscreteWaveletTransform[data, CDFWavelet[]];

{{0} -> {12, 12}, {1} -> {12, 12}, {2} -> {12, 12}, {3} -> {12, 
12}, {0, 0} -> {10, 10}, {0, 1} -> {10, 10}, {0, 2} -> {10, 
10}, {0, 3} -> {10, 10}, {0, 0, 0} -> {9, 9}, {0, 0, 1} -> {9, 
9}, {0, 0, 2} -> {9, 9}, {0, 0, 3} -> {9, 9}, {0, 0, 0, 0} -> {9, 
9}, {0, 0, 0, 1} -> {9, 9}, {0, 0, 0, 2} -> {9, 9}, {0, 0, 0, 
3} -> {9, 9}}

Here the dimensions of various decomposition levels is given as rules, e.g., $\{1\}\rightarrow \{12, 12\}$ means that the first LH decomposition matrix is of size $12 \times 12$.

What should I do? Should I simply truncate the matrices to nearest 2's power? or something else.

  • $\begingroup$ Do you have the possibility to test the code library.wolfram.com/infocenter/Demos/447 in 1D and check whether the same phenomenon happens? $\endgroup$ Aug 21, 2017 at 14:19
  • $\begingroup$ It would seem from the documentation that the returned decomposition signals (approximation and detail) are of power of two sizes. But it would a be a lot of work to use these for 2D transforms. Also, it is unclear how to specify filters for the CDFWavelet for the functions given (there is the option of specifying the low pass signal only, the high pass is automatically derived from it). After a lot of head-scratching, I think its best to use MATLAB with its dwtmode set to 'per'. I plan to use MATLink to connect MATLAB with the rest of the code in Mathematica at runtime. $\endgroup$
    – Iconoclast
    Aug 21, 2017 at 15:44
  • $\begingroup$ It wouldn't be such a lot of work, I believe. One DWT level on each row, then one on each column of the results, and so on on the low-pass/low-pass subband for the others levels $\endgroup$ Aug 21, 2017 at 16:04

1 Answer 1


First, for compression, it is neither advised to truncate the data nor to the nearest 2th power. First, for compression, it is generally better to expand the original image. After all, this in in use for JPEG DCT padding. Second, you can expand the image to the next integer divisible by $2^L$, where $L$ is the number of wavelet levels. For standard images, $L=4,5,6$ is sufficient, and this is less expansive than "the next power of two". If you expand the image smoothly (half-sample or whole-sample symmetry or antisymetry, depending on the image content), the expansion gets packed easily in the low-pass part of the wavelets, and does not cost a lot, if $2^L$ is sufficiently far away from the image size.

A contributed package apparently doing the job as expected is available with The Discrete Periodic Wavelet Transform in 1D by James F. Scholl at Wolfram Library Archive. It could be adapted to 2D.

Alternatively, you can dive in wavelets on the interval, or non-expansive filter banks, yet in my limited experience, the above scheme is relatively efficient and is perfect at first glance to focus on the essential.

  • 1
    $\begingroup$ thank you for your response. But I am a little confused. My image size is of perfect size (power of two). The problem is that when I apply the bior4.4 wavelet (CDF Wavelet) the sizes of different detail and approximation coefficient matrices is not a power of two (I have given example sizes that come out in the above code when applying periodic padding). Mathematica does not halve the sizes on each decomposition with the bior4.4 wavelet. What is the workaround? $\endgroup$
    – Iconoclast
    Aug 20, 2017 at 19:06
  • $\begingroup$ I do apologize, I probably answered too fast. Are your image $16 \times 16$ ? Such a small size can enter in conflict with filter length: 9/7 is about half the size. $\endgroup$ Aug 20, 2017 at 19:31
  • $\begingroup$ My image is of large size $(512 \times 512)$. The smallest image size that the 9/7 filter can handle is $9 \times 9$. The problem is not image size though. I used a small size just to illustrate. The problem is the size of wavelet decompositions. As an example the decompositions for $512 \times 512$ pixel image are $260 \times 260, 134 \times 134, 71 \times 71, 40 \times 40, 24 \times 24, 16 \times 16, 12 \times 12, 10 \times 10$ and $9 \times 9$ How do i construct a zero tree in such a scenario. $\endgroup$
    – Iconoclast
    Aug 20, 2017 at 19:41
  • $\begingroup$ I do not have access to Mathematica. There are however codes with non-expansive transformations for powers of two. Why do you use Mathematica to perform EZW coding? $\endgroup$ Aug 20, 2017 at 19:56
  • $\begingroup$ No particular reason. I just happen to be a heavy user of Mathematica. It does have some nice high-level programming features though. Making possible fast and efficient implementations of EZW. $\endgroup$
    – Iconoclast
    Aug 20, 2017 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.