(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 6.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 7] NotebookDataLength[ 11201, 347] NotebookOptionsPosition[ 9667, 297] NotebookOutlinePosition[ 10085, 313] CellTagsIndexPosition[ 10042, 310] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Lifting in JPEG2000", "Title", CellChangeTimes->{{3.41811592059375*^9, 3.418115924046875*^9}, { 3.42182906053125*^9, 3.421829063546875*^9}, {3.421832029796875*^9, 3.42183203246875*^9}}], Cell["\<\ Wavelet Workshop June 4-7, 2008 University of St. Thomas\ \>", "Subtitle", CellChangeTimes->{{3.421426484890625*^9, 3.42142648821875*^9}}], Cell["\<\ Catherine Beneteau Caroline Haddad David Ruch Patrick Van Fleet\ \>", "Subsubtitle", CellChangeTimes->{{3.42144927371875*^9, 3.42144928703125*^9}}], Cell[BoxData[ RowBox[{"<<", "DiscreteWavelets`DiscreteWavelets`"}]], "Input", CellChangeTimes->{{3.421832036421875*^9, 3.421832042203125*^9}}], Cell[CellGroupData[{ Cell["A Module for the LeGall Wavelet Transformation", "Section", CellChangeTimes->{{3.421832048*^9, 3.421832059609375*^9}}], Cell["\<\ Below is an example for computing the LeGall wavelet transformation. First \ we load a linear vector to help us see how the code works.\ \>", "Text", CellChangeTimes->{{3.421832072328125*^9, 3.421832094*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"v", "=", RowBox[{"Range", "[", "16", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"ListPlot", "[", RowBox[{"v", ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"PointSize", "[", ".015", "]"}]}]}], "]"}]}], "Input", CellChangeTimes->{{3.421832098953125*^9, 3.42183212059375*^9}, { 3.4218328376875*^9, 3.421832838046875*^9}}], Cell["\<\ The next step is to partition v into even and odd parts and append an extra \ value of the last element in the odd vector.\ \>", "Text", CellChangeTimes->{{3.421832158484375*^9, 3.42183219303125*^9}}], Cell[BoxData[{ RowBox[{"e", "=", RowBox[{"Take", "[", RowBox[{"v", ",", RowBox[{"{", RowBox[{"2", ",", RowBox[{"Length", "[", "v", "]"}], ",", "2"}], "}"}]}], "]"}]}], "\n", RowBox[{ RowBox[{"o", "=", RowBox[{"Take", "[", RowBox[{"v", ",", RowBox[{"{", RowBox[{"1", ",", RowBox[{"Length", "[", "v", "]"}], ",", "2"}], "}"}]}], "]"}]}], ";"}], "\n", RowBox[{"o", "=", RowBox[{"Append", "[", RowBox[{"o", ",", RowBox[{"Last", "[", "o", "]"}]}], "]"}]}]}], "Input", CellChangeTimes->{{3.421832200984375*^9, 3.421832211734375*^9}, { 3.421832838953125*^9, 3.421832839078125*^9}}], Cell["\<\ Next we pair up the elements in the odd vector, total up each pair and divide \ by 2.\ \>", "Text", CellChangeTimes->{{3.421832219140625*^9, 3.42183224284375*^9}}], Cell[BoxData[ RowBox[{"t", "=", RowBox[{ RowBox[{"Map", "[", RowBox[{"Total", ",", RowBox[{"Partition", "[", RowBox[{"o", ",", "2", ",", "1"}], "]"}]}], "]"}], "/", "2"}]}]], "Input", CellChangeTimes->{ 3.421832200984375*^9, {3.421832248859375*^9, 3.42183225346875*^9}, { 3.42183284009375*^9, 3.421832840265625*^9}}], Cell["We can use t to compute the differences", "Text", CellChangeTimes->{{3.42183226525*^9, 3.421832271140625*^9}}], Cell[BoxData[ RowBox[{" ", RowBox[{"d", "=", RowBox[{"e", "-", "t"}]}]}]], "Input", CellChangeTimes->{ 3.421832200984375*^9, {3.421832248859375*^9, 3.42183228640625*^9}, { 3.42183284146875*^9, 3.421832841578125*^9}}], Cell["\<\ Now we prepend the first element of d to d and drop the last element of o :\ \>", "Text", CellChangeTimes->{{3.42183229175*^9, 3.4218323214375*^9}}], Cell[BoxData[{ RowBox[{"d", "=", RowBox[{"Prepend", "[", RowBox[{"d", ",", RowBox[{"First", "[", "d", "]"}]}], "]"}]}], "\n", RowBox[{"o", "=", RowBox[{"Drop", "[", RowBox[{"o", ",", RowBox[{"-", "1"}]}], "]"}]}]}], "Input", CellChangeTimes->{ 3.421832200984375*^9, {3.421832248859375*^9, 3.42183228640625*^9}, { 3.4218323279375*^9, 3.4218323419375*^9}, 3.4218324745625*^9, { 3.42183284328125*^9, 3.421832843390625*^9}}], Cell["\<\ Next we compute the lowpass portion of the transformation - we partition the \ d vector into pairs, total up each pair, and divide the result by 4. We add \ this vector to o to get the lowpass portions.\ \>", "Text", CellChangeTimes->{{3.421832380609375*^9, 3.421832430640625*^9}}], Cell[BoxData[{ RowBox[{"t", "=", RowBox[{ RowBox[{"Map", "[", RowBox[{"Total", ",", RowBox[{"Partition", "[", RowBox[{"d", ",", "2", ",", "1"}], "]"}]}], "]"}], "/", "4"}]}], "\n", RowBox[{"s", "=", RowBox[{"o", "+", "t"}]}]}], "Input", CellChangeTimes->{ 3.421832200984375*^9, {3.421832248859375*^9, 3.42183228640625*^9}, { 3.4218323279375*^9, 3.42183233796875*^9}, {3.4218323696875*^9, 3.421832377234375*^9}, {3.4218324350625*^9, 3.421832444921875*^9}, { 3.4218328445625*^9, 3.42183284465625*^9}}], Cell["\<\ Finally, we drop the first element of d and join up s and d to obtain the \ transform!\ \>", "Text", CellChangeTimes->{{3.421832503921875*^9, 3.42183251790625*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"d", "=", RowBox[{"Drop", "[", RowBox[{"d", ",", "1"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"wt", "=", RowBox[{"Join", "[", RowBox[{"s", ",", "d"}], "]"}]}], " "}], "\[IndentingNewLine]", RowBox[{"ListPlot", "[", RowBox[{"wt", ",", RowBox[{"PlotStyle", "\[Rule]", RowBox[{"PointSize", "[", ".015", "]"}]}]}], "]"}]}], "Input", CellChangeTimes->{ 3.421832200984375*^9, {3.421832248859375*^9, 3.42183228640625*^9}, { 3.4218323279375*^9, 3.42183233796875*^9}, {3.4218323696875*^9, 3.421832377234375*^9}, 3.4218324350625*^9, {3.421832527953125*^9, 3.4218325588125*^9}, {3.421832692578125*^9, 3.421832699515625*^9}}], Cell[CellGroupData[{ Cell["Exercise 1", "Subsection", CellChangeTimes->{{3.421832565109375*^9, 3.4218325661875*^9}, { 3.4218327456875*^9, 3.42183274615625*^9}}], Cell[TextData[{ "Can you write a module ", StyleBox["MyLWT1D1", FontWeight->"Bold"], " that combines the ideas above? As extra credit, can you modify the module \ with two If statements AND an extra variable (a flag) so that it maps \ integers to integers?" }], "Text", CellChangeTimes->{{3.421832572265625*^9, 3.4218326159375*^9}, { 3.4218326555*^9, 3.421832668109375*^9}, {3.421832769484375*^9, 3.42183276984375*^9}}], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"MyLWT1D1", "[", "v_", "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"(*", " ", RowBox[{"Put", " ", "local", " ", "variables", " ", "here"}], " ", "*)"}], "}"}], ","}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"Put", " ", "commands", " ", "here"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.42183261740625*^9, 3.4218326401875*^9}}], Cell["Here is some code to test your module:", "Text", CellChangeTimes->{{3.42183264346875*^9, 3.42183264815625*^9}, { 3.42183268109375*^9, 3.421832682453125*^9}}], Cell[BoxData[{ RowBox[{"v", "=", RowBox[{"Range", "[", "16", "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"mywt", "=", RowBox[{"MyLWT1D1", "[", "v", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"wt", "=", RowBox[{"LWT1D1", "[", "v", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"Abs", "[", RowBox[{"mywt", "-", "wt"}], "]"}]}], "Input", CellChangeTimes->{{3.421832684359375*^9, 3.42183273534375*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Exercise 2", "Subsection", CellChangeTimes->{{3.421832565109375*^9, 3.4218325661875*^9}, { 3.4218327456875*^9, 3.421832754734375*^9}}], Cell[TextData[{ "Can you write a module ", StyleBox["MyILWT1D1", FontWeight->"Bold"], " that computes the inverse? As extra credit, can you modify the module \ with two If statements AND an extra variable (a flag) so that it maps \ integers to integers?" }], "Text", CellChangeTimes->{{3.421832572265625*^9, 3.4218326159375*^9}, { 3.4218326555*^9, 3.421832668109375*^9}, {3.4218327619375*^9, 3.421832780765625*^9}}], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"MyILWT1D1", "[", "v_", "]"}], ":=", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"(*", " ", RowBox[{"Put", " ", "local", " ", "variables", " ", "here"}], " ", "*)"}], "}"}], ","}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"Put", " ", "commands", " ", "here"}], " ", "*)"}], "\[IndentingNewLine]", "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.42183261740625*^9, 3.4218326401875*^9}, 3.421832784375*^9}], Cell["Here is some code to test your module:", "Text", CellChangeTimes->{{3.42183264346875*^9, 3.42183264815625*^9}, { 3.42183268109375*^9, 3.421832682453125*^9}}], Cell[BoxData[{ RowBox[{"v", "=", RowBox[{"Range", "[", "16", "]"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"mywt", "=", RowBox[{"MyLWT1D1", "[", "v", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"newv", "=", RowBox[{"MyILWT1D1", "[", "v", "]"}]}], "\[IndentingNewLine]", RowBox[{"Abs", "[", RowBox[{"v", "-", "newv"}], "]"}]}], "Input", CellChangeTimes->{{3.421832684359375*^9, 3.42183273534375*^9}, { 3.421832790828125*^9, 3.421832822328125*^9}}] }, Open ]] }, Open ]] }, Open ]] }, WindowSize->{1016, 651}, WindowMargins->{{0, Automatic}, {Automatic, 0}}, FrontEndVersion->"6.0 for Microsoft Windows (32-bit) (April 20, 2007)", StyleDefinitions->FrontEnd`FileName[{"Creative"}, "NaturalColor.nb", CharacterEncoding -> "WindowsANSI"] ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[590, 23, 197, 3, 73, "Title"], Cell[790, 28, 149, 5, 96, "Subtitle"], Cell[942, 35, 158, 6, 89, "Subsubtitle"], Cell[1103, 43, 144, 2, 41, "Input"], Cell[CellGroupData[{ Cell[1272, 49, 125, 1, 75, "Section"], Cell[1400, 52, 220, 4, 29, "Text"], Cell[1623, 58, 379, 9, 62, "Input"], Cell[2005, 69, 211, 4, 29, "Text"], Cell[2219, 75, 654, 20, 82, "Input"], Cell[2876, 97, 174, 4, 29, "Text"], Cell[3053, 103, 351, 10, 41, "Input"], Cell[3407, 115, 117, 1, 29, "Text"], Cell[3527, 118, 232, 6, 41, "Input"], Cell[3762, 126, 159, 3, 29, "Text"], Cell[3924, 131, 456, 12, 62, "Input"], Cell[4383, 145, 293, 5, 47, "Text"], Cell[4679, 152, 542, 13, 62, "Input"], Cell[5224, 167, 175, 4, 29, "Text"], Cell[5402, 173, 718, 17, 82, "Input"], Cell[CellGroupData[{ Cell[6145, 194, 142, 2, 37, "Subsection"], Cell[6290, 198, 431, 10, 47, "Text"], Cell[6724, 210, 501, 13, 82, "Input"], Cell[7228, 225, 166, 2, 29, "Text"], Cell[7397, 229, 443, 11, 102, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[7877, 245, 143, 2, 37, "Subsection"], Cell[8023, 249, 427, 10, 47, "Text"], Cell[8453, 261, 525, 14, 82, "Input"], Cell[8981, 277, 166, 2, 29, "Text"], Cell[9150, 281, 477, 11, 102, "Input"] }, Open ]] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)