Discrete Wavelets with Applications

063 - The Two-dimensional Haar Wavelet Transform

Helmut  Knaust - Department of Mathematical Sciences, University of Texas at El Paso, hknaust@utep.edu
10/18/2010. Last  edits 05/01/2024.

SetDirectory[NotebookDirectory[]];<<DW.wl
SetDirectory["Images//Grayscale"];

The Haar Matrix

?Haar

MatrixForm[Haar[6]]

MatrixForm[Haar[6].Transpose[Haar[6]]]

MatrixForm[Chop[Haar[6].Transpose[Haar[6]]]]

First Examples

pic=Import["tram.png","Data"];
ImagePlot[pic]

Dimensions[pic]

ImagePlot[pic.Transpose[Haar[768]],Scaled->False]

? ImagePlot

ImagePlot[Haar[512].pic,Scaled->False]

TransformPlot[Haar[512].pic.Transpose[Haar[768]],1]

?TransformPlot

Applying the 2D Haar Wavelet  Transform

ImagePlot[pic]
ShannonEntropy[pic]
CEnergy[pic]
FrequencyHistogram[pic]

?HaarWLT

TransformPlot[pc=HaarWLT[pic],1]
ShannonEntropy[pc]

{{"B","V"},{"H","D"}}

{r,c}=Dimensions[pic];hwl[n_]:=HaarWLT[pic,n]
GraphicsGrid [{{ImagePlot[hwl[1][[1;;r/2,1;;c/2]],Scaled->False,PixelConstrained->2,PlotLabel->"B"],
ImagePlot[hwl[1][[1;;r/2,c/2+1;;c]],Scaled->False,PixelConstrained->2,PlotLabel->"V"]},{ImagePlot[hwl[1][[r/2+1;;r,1;;c/2]],Scaled->False,PixelConstrained->2,PlotLabel->"H"],
ImagePlot[hwl[1][[r/2+1;;r,c/2+1;;c]],Scaled->False,PixelConstrained->2,PlotLabel->"D"]}},ImageSize->1200]

Iterating the 2D Haar Wavelet Transfrom

TransformPlot[pc=HaarWLT[pic,2],2]
ShannonEntropy[pc]

TransformPlot[pc=HaarWLT[pic,3],3]
ShannonEntropy[pc]

pc=Round[pc];
CEnergy[pc]
FrequencyHistogram[pc]

Max[pc]
Min[pc]

There are quite a few “0” entries in the transformed matrix:

Count[Flatten[pc],0]