<p>The picture shows a 2 level wavelet transform. For the low-pass and high-pass filters, I have used the same of the JPEG2000, lossy transform, so that this is the wavelet that is used in the JPEG2000 format. In general, it is quite hard to show a wavelet transform properly, because of the different ranges of the different parts. I have made the following choices.
</p><p>First of all, I wanted to use a picture with both flat surfaces, sharp edges and details. The standard test image Lenna is commonly used for this purpose, but I didn't want to use it because it is not in the public domain. I took a look at the big featured picture gallery con Commons and I have chosen <a href="//commons.wikimedia.org/wiki/File:Lichtenstein_img_processing_test.png" title="File:Lichtenstein img processing test.png">Image:Lichtenstein img processing test.png</a> because it has lots of details in the bottom left, while the top right has almost no details because of the sky. Moreover, the edges of the castle are really sharp, so they can be clearly seen in the wavelet transform.
</p><p>I have saved the original image in a file called <i>lichtenstein.png</i>, to make it simpler.
</p><p>Then I have used the following Matlab script:
</p>
<div class="mw-highlight mw-highlight-lang-matlab mw-content-ltr" dir="ltr"><pre><span></span><span class="nb">clear</span><span class="w"> </span><span class="nb">all</span>

<span class="c">%input must be 512x512</span>
<span class="n">img</span><span class="p">=</span><span class="nb">imread</span><span class="p">(</span><span class="s">'lichtenstein.png'</span><span class="p">);</span>

<span class="n">img</span><span class="p">=</span><span class="nb">im2double</span><span class="p">(</span><span class="n">img</span><span class="p">);</span>
<span class="n">img</span><span class="p">=</span><span class="nb">rgb2gray</span><span class="p">(</span><span class="n">img</span><span class="p">);</span>

<span class="c">% filters in JPEG2000</span>
<span class="n">Lo_D</span><span class="p">=[</span><span class="mf">0.0267</span><span class="w"> </span><span class="o">-</span><span class="mf">0.0168</span><span class="w"> </span><span class="o">-</span><span class="mf">0.0782</span><span class="w"> </span><span class="mf">0.2668</span><span class="w"> </span><span class="mf">0.6029</span><span class="w"> </span><span class="mf">0.2668</span><span class="w"> </span><span class="o">-</span><span class="mf">0.0782</span><span class="w"> </span><span class="o">-</span><span class="mf">0.0168</span><span class="w"> </span><span class="mf">0.0267</span><span class="p">];</span>
<span class="n">Hi_D</span><span class="p">=[</span><span class="mf">0.0912</span><span class="w"> </span><span class="o">-</span><span class="mf">0.0575</span><span class="w"> </span><span class="o">-</span><span class="mf">0.5912</span><span class="w"> </span><span class="mf">1.1150</span><span class="w"> </span><span class="o">-</span><span class="mf">0.5912</span><span class="w"> </span><span class="o">-</span><span class="mf">0.0575</span><span class="w"> </span><span class="mf">0.0912</span><span class="p">];</span>

<span class="c">%calculate the 2-level Wavelet transform</span>
<span class="p">[</span><span class="n">scaled</span><span class="p">,</span><span class="w"> </span><span class="n">vertical</span><span class="p">,</span><span class="w"> </span><span class="n">horizontal</span><span class="p">,</span><span class="w"> </span><span class="n">diagonal</span><span class="p">]=</span><span class="n">dwt2</span><span class="p">(</span><span class="n">img</span><span class="p">,</span><span class="n">Lo_D</span><span class="p">,</span><span class="n">Hi_D</span><span class="p">);</span>
<span class="p">[</span><span class="n">scaled2</span><span class="p">,</span><span class="w"> </span><span class="n">vertical2</span><span class="p">,</span><span class="w"> </span><span class="n">horizontal2</span><span class="p">,</span><span class="w"> </span><span class="n">diagonal2</span><span class="p">]=</span><span class="n">dwt2</span><span class="p">(</span><span class="n">scaled</span><span class="p">,</span><span class="n">Lo_D</span><span class="p">,</span><span class="n">Hi_D</span><span class="p">);</span>

<span class="c">%crop pictures (for displaying purpose)</span>
<span class="n">scaled2</span><span class="p">=</span><span class="n">imcrop</span><span class="p">(</span><span class="n">scaled2</span><span class="p">,[</span><span class="mi">4</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="mi">127</span><span class="w"> </span><span class="mi">127</span><span class="p">]);</span>
<span class="n">horizontal2</span><span class="p">=</span><span class="n">imcrop</span><span class="p">(</span><span class="n">horizontal2</span><span class="p">,[</span><span class="mi">4</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="mi">127</span><span class="w"> </span><span class="mi">127</span><span class="p">]);</span>
<span class="n">vertical2</span><span class="p">=</span><span class="n">imcrop</span><span class="p">(</span><span class="n">vertical2</span><span class="p">,[</span><span class="mi">4</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="mi">127</span><span class="w"> </span><span class="mi">127</span><span class="p">]);</span>
<span class="n">diagonal2</span><span class="p">=</span><span class="n">imcrop</span><span class="p">(</span><span class="n">diagonal2</span><span class="p">,[</span><span class="mi">4</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="mi">127</span><span class="w"> </span><span class="mi">127</span><span class="p">]);</span>
<span class="n">horizontal</span><span class="p">=</span><span class="n">imcrop</span><span class="p">(</span><span class="n">horizontal</span><span class="p">,[</span><span class="mi">4</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="mi">255</span><span class="w"> </span><span class="mi">255</span><span class="p">]);</span>
<span class="n">vertical</span><span class="p">=</span><span class="n">imcrop</span><span class="p">(</span><span class="n">vertical</span><span class="p">,[</span><span class="mi">4</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="mi">255</span><span class="w"> </span><span class="mi">255</span><span class="p">]);</span>
<span class="n">diagonal</span><span class="p">=</span><span class="n">imcrop</span><span class="p">(</span><span class="n">diagonal</span><span class="p">,[</span><span class="mi">4</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="mi">255</span><span class="w"> </span><span class="mi">255</span><span class="p">]);</span>

<span class="c">%increase contrast (for displaying purpose)</span>
<span class="n">vertical</span><span class="p">=</span><span class="n">imadjust</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">vertical</span><span class="p">));</span>
<span class="n">horizontal</span><span class="p">=</span><span class="n">imadjust</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">horizontal</span><span class="p">));</span>
<span class="n">diagonal</span><span class="p">=</span><span class="n">imadjust</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">diagonal</span><span class="p">));</span>
<span class="n">vertical2</span><span class="p">=</span><span class="n">imadjust</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">vertical2</span><span class="p">));</span>
<span class="n">horizontal2</span><span class="p">=</span><span class="n">imadjust</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">horizontal2</span><span class="p">));</span>
<span class="n">diagonal2</span><span class="p">=</span><span class="n">imadjust</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">diagonal2</span><span class="p">));</span>

<span class="c">%put them all together</span>
<span class="nb">transform</span><span class="p">=</span><span class="nb">zeros</span><span class="p">(</span><span class="mi">512</span><span class="p">,</span><span class="mi">512</span><span class="p">);</span>

<span class="nb">transform</span><span class="p">(</span><span class="mi">1</span><span class="p">:</span><span class="mi">128</span><span class="p">,</span><span class="mi">1</span><span class="p">:</span><span class="mi">128</span><span class="p">)=</span><span class="n">scaled2</span><span class="p">;</span>
<span class="nb">transform</span><span class="p">(</span><span class="mi">1</span><span class="p">:</span><span class="mi">128</span><span class="p">,</span><span class="mi">129</span><span class="p">:</span><span class="mi">256</span><span class="p">)=</span><span class="n">horizontal2</span><span class="p">;</span>
<span class="nb">transform</span><span class="p">(</span><span class="mi">129</span><span class="p">:</span><span class="mi">256</span><span class="p">,</span><span class="mi">1</span><span class="p">:</span><span class="mi">128</span><span class="p">)=</span><span class="n">vertical2</span><span class="p">;</span>
<span class="nb">transform</span><span class="p">(</span><span class="mi">129</span><span class="p">:</span><span class="mi">256</span><span class="p">,</span><span class="mi">129</span><span class="p">:</span><span class="mi">256</span><span class="p">)=</span><span class="n">diagonal2</span><span class="p">;</span>
<span class="nb">transform</span><span class="p">(</span><span class="mi">1</span><span class="p">:</span><span class="mi">256</span><span class="p">,</span><span class="mi">257</span><span class="p">:</span><span class="mi">512</span><span class="p">)=</span><span class="n">horizontal</span><span class="p">;</span>
<span class="nb">transform</span><span class="p">(</span><span class="mi">257</span><span class="p">:</span><span class="mi">512</span><span class="p">,</span><span class="mi">1</span><span class="p">:</span><span class="mi">256</span><span class="p">)=</span><span class="n">vertical</span><span class="p">;</span>
<span class="nb">transform</span><span class="p">(</span><span class="mi">257</span><span class="p">:</span><span class="mi">512</span><span class="p">,</span><span class="mi">257</span><span class="p">:</span><span class="mi">512</span><span class="p">)=</span><span class="n">diagonal</span><span class="p">;</span>

<span class="nb">imwrite</span><span class="p">(</span><span class="nb">transform</span><span class="p">,</span><span class="s">'Jpeg2000_2-level_wavelet_transform-lichtenstein.png'</span><span class="p">);</span>
</pre></div>
<p>If I had placed all the transforms one next to the other, I would have got a picture wider than 512x512, with some odd behaviour close to the edges. In order to avoid those problems, I have cropped the transforms so that I can easily put one next to the other to get a 512x512 picture. In general, it is not a good idea to discard information, but here I just wanted to create a simple and clear example.
</p>
In order to show the derivatives, I have taken the absolute values (I want to show the magnitude of the derivative), then I have improved the contrast to make them look clearer.
<a href="//commons.wikimedia.org/wiki/User:Alejo2083" title="User:Alejo2083">Alessio Damato</a>
CC BY-SA 3.0
<span class="int-own-work" lang="en">Own work</span>