(* 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[ 11320, 357] NotebookOptionsPosition[ 10098, 315] NotebookOutlinePosition[ 10516, 331] CellTagsIndexPosition[ 10473, 328] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Building the Biorthogonal Wavelet Transformation Matrices", "Subtitle", CellChangeTimes->{{3.417776306955002*^9, 3.417776318923828*^9}}], Cell[BoxData[ RowBox[{"<<", "DiscreteWavelets`DiscreteWavelets`"}]], "Input", CellChangeTimes->{{3.417775649825796*^9, 3.417775655685209*^9}, { 3.4177768835055666`*^9, 3.4177768838805695`*^9}}], Cell[CellGroupData[{ Cell["Load the Filters", "Section", CellChangeTimes->{{3.4177763373458214`*^9, 3.417776348252141*^9}}], Cell[TextData[{ "The command SplineFilters loads biorthogonal spline filters. The second \ index is one less than the length of ", Cell[BoxData[ FormBox[ OverscriptBox["h", "~"], TraditionalForm]]], " and the first index is the stopping index of h if the length of h is odd \ or one less than the stopping index of h if the length of h is even." }], "Text", CellChangeTimes->{{3.417776355033435*^9, 3.4177764425496197`*^9}}], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"{", RowBox[{"h", ",", "ht"}], "}"}], "=", RowBox[{"SplineFilters", "[", RowBox[{"2", ",", "2"}], "]"}]}], ";"}]], "Input", CellChangeTimes->{{3.4177756614039955`*^9, 3.417775755826475*^9}, { 3.417775807311179*^9, 3.417775917093132*^9}, {3.4177760161093903`*^9, 3.4177761090631104`*^9}, {3.4177762053606014`*^9, 3.41777623167327*^9}, 3.4177764462996435`*^9}], Cell[TextData[{ "Now we build ", Cell[BoxData[ FormBox[ OverscriptBox["H", "~"], TraditionalForm]]] }], "Text", CellChangeTimes->{{3.4177764492371626`*^9, 3.4177764717998066`*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"r1", "=", RowBox[{"RotateLeft", "[", RowBox[{ RowBox[{"Join", "[", RowBox[{"ht", ",", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", "7", "}"}]}], "]"}]}], "]"}], ",", "1"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Hw", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"RotateRight", "[", RowBox[{"r1", ",", RowBox[{"2", "*", "k"}]}], "]"}], ",", RowBox[{"{", RowBox[{"k", ",", "0", ",", "4"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", RowBox[{"MatrixForm", "[", "Hw", "]"}]}], "]"}], ";"}]}], "Input", CellChangeTimes->{{3.4177756614039955`*^9, 3.417775755826475*^9}, { 3.417775807311179*^9, 3.417775917093132*^9}, {3.4177760161093903`*^9, 3.4177761090631104`*^9}, {3.4177762053606014`*^9, 3.41777623167327*^9}, 3.4177764462996435`*^9, 3.417776477612344*^9}], Cell[TextData[{ "Then ", Cell[BoxData[ FormBox[ OverscriptBox["G", "~"], TraditionalForm]]] }], "Text", CellChangeTimes->{{3.417776481331118*^9, 3.4177764925186896`*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"gt", "=", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "1", ",", RowBox[{"-", "1"}], ",", "1", ",", RowBox[{"-", "1"}]}], "}"}], "*", "h"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"r2", "=", RowBox[{"RotateLeft", "[", RowBox[{ RowBox[{"Join", "[", RowBox[{"gt", ",", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", "5", "}"}]}], "]"}]}], "]"}], ",", "1"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Gw", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"RotateRight", "[", RowBox[{"r2", ",", RowBox[{"2", "*", "k"}]}], "]"}], ",", RowBox[{"{", RowBox[{"k", ",", "0", ",", "4"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", RowBox[{"MatrixForm", "[", "Gw", "]"}]}], "]"}], ";"}]}], "Input", CellChangeTimes->{{3.4177756614039955`*^9, 3.417775755826475*^9}, { 3.417775807311179*^9, 3.417775917093132*^9}, {3.4177760161093903`*^9, 3.4177761090631104`*^9}, {3.4177762053606014`*^9, 3.41777623167327*^9}, 3.4177764462996435`*^9, {3.417776477612344*^9, 3.417776496987468*^9}}], Cell[TextData[{ "We join these matrices to form ", Cell[BoxData[ FormBox[ OverscriptBox["W", "~"], TraditionalForm]]] }], "Text", CellChangeTimes->{{3.4177765369564743`*^9, 3.417776548706549*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"Wt", "=", RowBox[{"Join", "[", RowBox[{"Hw", ",", "Gw"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", RowBox[{"MatrixForm", "[", "Wt", "]"}]}], "]"}], ";"}]}], "Input", CellChangeTimes->{{3.4177756614039955`*^9, 3.417775755826475*^9}, { 3.417775807311179*^9, 3.417775917093132*^9}, {3.4177760161093903`*^9, 3.4177761090631104`*^9}, {3.4177762053606014`*^9, 3.41777623167327*^9}, 3.4177764462996435`*^9, {3.417776477612344*^9, 3.417776496987468*^9}, 3.4177765615972567`*^9}], Cell["Next we build matrix W.", "Text", CellChangeTimes->{{3.417776564659776*^9, 3.4177765706285644`*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"r1", "=", RowBox[{"RotateLeft", "[", RowBox[{ RowBox[{"Join", "[", RowBox[{"h", ",", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", "5", "}"}]}], "]"}]}], "]"}], ",", "2"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"H", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"RotateRight", "[", RowBox[{"r1", ",", RowBox[{"2", "*", "k"}]}], "]"}], ",", RowBox[{"{", RowBox[{"k", ",", "0", ",", "4"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", RowBox[{"MatrixForm", "[", "H", "]"}]}], "]"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"g", "=", RowBox[{ RowBox[{"{", RowBox[{"1", ",", RowBox[{"-", "1"}], ",", "1"}], "}"}], "*", "ht"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"r2", "=", RowBox[{"Join", "[", RowBox[{"g", ",", RowBox[{"Table", "[", RowBox[{"0", ",", RowBox[{"{", "7", "}"}]}], "]"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"G", "=", RowBox[{"Table", "[", RowBox[{ RowBox[{"RotateRight", "[", RowBox[{"r2", ",", RowBox[{"2", "*", "k"}]}], "]"}], ",", RowBox[{"{", RowBox[{"k", ",", "0", ",", "4"}], "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", RowBox[{"MatrixForm", "[", "G", "]"}]}], "]"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"W", "=", RowBox[{"Join", "[", RowBox[{"H", ",", "G"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"Print", "[", RowBox[{"\"\\"", ",", RowBox[{"MatrixForm", "[", "W", "]"}]}], "]"}], ";"}]}], "Input", CellChangeTimes->{{3.4177761220319433`*^9, 3.4177761890167475`*^9}, { 3.417776242485839*^9, 3.417776295533054*^9}, {3.417776886646212*^9, 3.4177768868962135`*^9}}], Cell[TextData[{ "To check our work, we multiply W and ", Cell[BoxData[ FormBox[ SuperscriptBox[ OverscriptBox["W", "~"], "T"], TraditionalForm]]] }], "Text", CellChangeTimes->{{3.4177765768786044`*^9, 3.417776624332033*^9}}], Cell[BoxData[ RowBox[{"MatrixForm", "[", RowBox[{"W", ".", RowBox[{"Transpose", "[", "Wt", "]"}]}], "]"}]], "Input", CellChangeTimes->{{3.4177762706578946`*^9, 3.417776280517333*^9}, { 3.417776888568099*^9, 3.4177768888962264`*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Biorthogonal Wavelet Transformation", "Section", CellChangeTimes->{{3.417776638378998*^9, 3.4177766433477798`*^9}}], Cell["\<\ We can apply the (5, 3) filter using the DiscreteWavelets package. The \ commands are BWT1D and BWT2D for one- and two-dimensional input respectively. \ You must also supply a biorthogonal filter pair and a number of iterations.\ \>", "Text", CellChangeTimes->{{3.417776650175948*^9, 3.4177766966293707`*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"img", "=", RowBox[{"ImageNames", "[", RowBox[{"ImageType", "\[Rule]", "GrayScale"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"A", "=", RowBox[{"ImageRead", "[", RowBox[{"img", "[", RowBox[{"[", "4", "]"}], "]"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"ImagePlot", "[", "A", "]"}]}], "Input", CellChangeTimes->{{3.417776699488764*^9, 3.4177767613172846`*^9}, { 3.417776801911295*^9, 3.4177768144895*^9}, {3.4177768522241163`*^9, 3.41777689105249*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"its", "=", "3"}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"B", "=", RowBox[{"BWT2D", "[", RowBox[{ RowBox[{"N", "[", "A", "]"}], ",", RowBox[{"{", RowBox[{"h", ",", "ht"}], "}"}], ",", RowBox[{"NumIterations", "\[Rule]", "its"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"WaveletDensityPlot", "[", RowBox[{"B", ",", RowBox[{"NumIterations", "\[Rule]", "its"}]}], "]"}]}], "Input", CellChangeTimes->{{3.417776699488764*^9, 3.4177767613172846`*^9}, { 3.417776801911295*^9, 3.4177768144895*^9}, 3.4177768522241163`*^9, { 3.417776892083747*^9, 3.417776892255623*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Repeat the Construction Above for the (8, 4) Filter Pair", "Section", CellChangeTimes->{{3.4177768940368843`*^9, 3.4177769123026257`*^9}}], Cell["\<\ Can you find the transform matrices for the (8, 4) filter pair?\ \>", "Text", CellChangeTimes->{{3.417776917005781*^9, 3.417776929865238*^9}}] }, Open ]] }, Open ]] }, WindowSize->{1272, 683}, 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, 143, 1, 36, "Subtitle"], Cell[736, 26, 197, 3, 41, "Input"], Cell[CellGroupData[{ Cell[958, 33, 103, 1, 75, "Section"], Cell[1064, 36, 434, 9, 49, "Text"], Cell[1501, 47, 430, 10, 41, "Input"], Cell[1934, 59, 188, 6, 31, "Text"], Cell[2125, 67, 1006, 28, 82, "Input"], Cell[3134, 97, 178, 6, 31, "Text"], Cell[3315, 105, 1273, 37, 102, "Input"], Cell[4591, 144, 204, 6, 31, "Text"], Cell[4798, 152, 603, 13, 62, "Input"], Cell[5404, 167, 107, 1, 29, "Text"], Cell[5514, 170, 2023, 66, 202, "Input"], Cell[7540, 238, 236, 7, 32, "Text"], Cell[7779, 247, 243, 5, 41, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[8059, 257, 122, 1, 75, "Section"], Cell[8184, 260, 322, 5, 47, "Text"], Cell[8509, 267, 550, 14, 82, "Input"], Cell[9062, 283, 670, 17, 82, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[9769, 305, 145, 1, 75, "Section"], Cell[9917, 308, 153, 3, 29, "Text"] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)