Project 04 (40 points total)

Due November 20, 2012

Problem 1 (10 points)

Write two modules (if necessary) StreamEncoding and StreamDecoding for Huffman encoding and decoding. Inputs to the first module should be a character string and a coding table; the output should be a binary sequence encoding the character string.

cstr="ABRACADABRA"

huff = {{"A", "0"}, {"R", "111"}, {"B", "10"}, {"D", "1101"}, {"C", "1100"}}

Here is how your commands should work:

bstring=StreamEncoding[cstr,huff]

The second module should have as inputs a binary string and a coding table and output the corresponding character string:

StreamDecoding[bstring,huff]

You will need to consult the help section to find out about strings and replacement operators; the next command may be useful to rewrite the coding table as a list of replacement rules:

Apply[Rule,huff,2]

Problem 2 (15 points)

Write a procedure (preferably a module) to graph a function and its approximation in the vector space (Subscript[V, 4 ]) defined in the handout "Multi-resolution Analysis".

Here is the definition of the father wavelet and the plot of one of the elements in (Subscript[V, 4]).
You obtain ϕ and ψ by typing Esc f Esc and EscpsEsc, respectively.

ϕ[x_]=Piecewise[{{1,0≤x<1}},0]

Plot[1 4ϕ[16x]+1/4 4 ϕ[16x-7]+1/3 4 ϕ[16x-12]+1/2 4 ϕ[16x-13],{x,0,1},PlotStyle->{Blue,Thick}]

Here is an example how to graph two functions simultaneously :

Plot[{Sqrt[x],x^2},{x,0,1},PlotStyle->{{Blue,Dashed},{Red,Thick}}]

Problem 3 (15 points)

Let' s import a picture :

SetDirectory[NotebookDirectory[]];<<DW.m
SetDirectory["Images\\Grayscale"];
pic=Import["car.png","Data"];
ImagePlot[pic,Scaled->True]

In Notebook  0631 the following module from 'DW.m' (with a different name) is used to apply the Haar Transform ' n' times to a matrix ' pic':

HaarWLTransform[pic_, n_] := 
 Module[{pc = pic, r = Dimensions[pic][[1]], c = Dimensions[pic][[2]]},
  	Do[ pc[[1 ;; r/2^k, 1 ;; c/2^k]] =Haar[r/2^k].pc[[1 ;; r/2^k, 1 ;; c/2^k]].Transpose[Haar[c/2^k]], {k, 0, n - 1,1}]; 
  	Return[pc];]

pic2=HaarWLTransform[pic,1];
ImagePlot[pic2]
TransformPlot[pic2,1]

pic2=HaarWLTransform[pic,3];
TransformPlot[pic2,3]

Write a module ' InverseHaarWLTransform[pic_, n_]'  to apply the inverse Haar Transform 'n' times to the matrix ' pic'.

Check (using PSNR) that if you apply the Haar transform three times and then your module (with n=3), you obtain the original image back (modulo loss due to round-off errors).