(* 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[ 17103, 571] NotebookOptionsPosition[ 14911, 497] NotebookOutlinePosition[ 15329, 513] CellTagsIndexPosition[ 15286, 510] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Haar Transform 2D", "Title"], Cell["\<\ David Ruch and Patrick J. Van Fleet Minicourse #4, January 2008 Joint Mathematics Meetings San Diego, CA\ \>", "Subsubtitle", CellChangeTimes->{{3.4085655291875*^9, 3.408565543609375*^9}, { 3.40865754803125*^9, 3.408657550109375*^9}}], Cell[CellGroupData[{ Cell["Objective", "Section"], Cell["\<\ In this notebook, we will explore the two-dimensional discrete Haar wavelet \ transform.\ \>", "Text"] }, Open ]], Cell[CellGroupData[{ Cell["Conventions", "Section"], Cell[TextData[{ "This notebook uses the package ", StyleBox["DiscreteWavelets", FontColor->RGBColor[1, 0, 0]], " (written by Patrick Van Fleet). All commands from the ", StyleBox["DiscreteWavelets", FontColor->RGBColor[1, 0, 0]], " library will be denoted in ", StyleBox["red", FontColor->RGBColor[1, 0, 0]], ". Help is available for every command in ", StyleBox["the package", FontColor->GrayLevel[0]], ". Click on Help and then Documentation Center. At the bottom-right of the \ page is a link for Installed AddOns. Click this link and one of the options \ is DiscreteWavelets. Click this link to go to the Help Browser. Like all ", StyleBox["Mathematica", FontSlant->"Italic"], " help screens, the help is \"live\" - you can either execute the commands \ in the help to see the effects of the command or cut and paste them into your \ own notebook.\n\nComments are useful within cells of code. Any code enclosed \ by (* *) is a comment and ignored by the ", StyleBox["Mathematica", FontSlant->"Italic"], " kernel." }], "Text", CellChangeTimes->{{3.4085631561875*^9, 3.408563201375*^9}, { 3.4085632433125*^9, 3.408563315796875*^9}, {3.40856339940625*^9, 3.4085634034375*^9}, {3.408565167890625*^9, 3.40856516825*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Load DiscreteWavelets", "Section", CellChangeTimes->{3.408563584328125*^9}], Cell[BoxData[ RowBox[{"<<", "DiscreteWavelets`DiscreteWavelets`"}]], "Input", CellChangeTimes->{{3.408563455078125*^9, 3.408563467234375*^9}, { 3.408565207546875*^9, 3.40856520834375*^9}, {3.4085675625625*^9, 3.408567562828125*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Two-Dimensional Discrete Haar Transform Modules", "Section"], Cell[TextData[{ "\nWe will use the 2D modules from ", StyleBox["DiscreteWavelets", FontColor->RGBColor[1, 0, 0]], " to compute Haar Transforms of matrices. The modules are ", StyleBox["HWT2D", FontColor->RGBColor[1, 0, 0]], " and ", StyleBox["IHWT2D", FontColor->RGBColor[1, 0, 0]], ". Both modules require two arguments. The first is the input matrix. The \ second argument is the number of iterations." }], "Text", CellChangeTimes->{{3.40856574871875*^9, 3.40856575571875*^9}, { 3.408565790390625*^9, 3.408565821390625*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Available Images", "Section", CellChangeTimes->{{3.408566424859375*^9, 3.40856642509375*^9}, { 3.40856666034375*^9, 3.40856666378125*^9}}], Cell[TextData[{ "The ", StyleBox["DiscreteWavelets", FontColor->RGBColor[1, 0, 0]], " packages comes with 18 grayscale images. You can see information about \ these images (name, size, etc.) by issuing the command ", StyleBox["ImageList", FontColor->RGBColor[1, 0, 0]], "." }], "Text", CellChangeTimes->{{3.40856643015625*^9, 3.408566482328125*^9}}], Cell[BoxData[ RowBox[{ StyleBox["ImageList", FontColor->RGBColor[1, 0, 0]], "[", RowBox[{"ImageType", "\[Rule]", "GrayScale"}], "]"}]], "Input", CellChangeTimes->{{3.408566491578125*^9, 3.40856650215625*^9}, { 3.408567558484375*^9, 3.408567558796875*^9}}], Cell[TextData[{ "You can also get a look at these images by using the command ", StyleBox["ShowThumbnails", FontColor->RGBColor[1, 0, 0]], ". " }], "Text", CellChangeTimes->{{3.408635831734375*^9, 3.40863590271875*^9}}], Cell[BoxData[ RowBox[{ StyleBox["ShowThumbnails", FontColor->RGBColor[1, 0, 0]], "[", RowBox[{"ImageType", "\[Rule]", "GrayScale"}], "]"}]], "Input", CellChangeTimes->{{3.408635905203125*^9, 3.408635912609375*^9}}], Cell[TextData[{ StyleBox["NOTE:", FontWeight->"Bold"], " In ", StyleBox["Mathematica", FontSlant->"Italic"], " 5.2, ShowThumbnails does not exist - use the following command." }], "Text", CellChangeTimes->{{3.408635831734375*^9, 3.408635924390625*^9}, { 3.40863602578125*^9, 3.408636028421875*^9}}], Cell[BoxData[ RowBox[{ RowBox[{ StyleBox["ImageNames", FontColor->RGBColor[1, 0, 0]], "[", RowBox[{ RowBox[{"ImageType", "\[Rule]", "GrayScale"}], ",", RowBox[{"Thumbnails", "\[Rule]", "True"}]}], "]"}], ";"}]], "Input", CellChangeTimes->{{3.408635940671875*^9, 3.4086359565625*^9}}], Cell[TextData[{ "No matter where you installed the ", StyleBox["DiscreteWavelets", FontColor->RGBColor[1, 0, 0]], " package on your computer, you can retrieve the absolute path and file name \ for each included image. The command ", StyleBox["ImageNames", FontColor->RGBColor[1, 0, 0]], " produces a list of file names." }], "Text", CellChangeTimes->{{3.40856651390625*^9, 3.408566597796875*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"gray", "=", RowBox[{ StyleBox["ImageNames", FontColor->RGBColor[1, 0, 0]], "[", RowBox[{"ImageType", "\[Rule]", "GrayScale"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"gray", "[", RowBox[{"[", "1", "]"}], "]"}]}], "Input", CellChangeTimes->{{3.40856660190625*^9, 3.40856662253125*^9}, { 3.408567556296875*^9, 3.4085675565625*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Loading and Plotting Images", "Section", CellChangeTimes->{{3.40856667084375*^9, 3.40856669671875*^9}}], Cell["\<\ Once you have the list of file names, it is very easy to load and plot \ images. Let's load the first image in the list.\ \>", "Text", CellChangeTimes->{{3.408566678375*^9, 3.408566710125*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"A", "=", RowBox[{ StyleBox["ImageRead", FontColor->RGBColor[1, 0, 0]], "[", RowBox[{"gray", "[", RowBox[{"[", "1", "]"}], "]"}], "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ StyleBox["ImagePlot", FontColor->RGBColor[1, 0, 0]], "[", "A", "]"}]}], "Input", CellChangeTimes->{{3.408566701640625*^9, 3.408566736734375*^9}, { 3.408567553625*^9, 3.408567553875*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Using HWT2D", "Section", CellChangeTimes->{3.408662937296875*^9}], Cell["\<\ In the cell below, we compute and plot the two-dimensional HWT of image A. \ We compute the transform of N[A] to speed up the computation.\ \>", "Text", CellChangeTimes->{{3.408566859109375*^9, 3.408566871125*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{ StyleBox["B", FontColor->GrayLevel[0]], " ", "=", " ", RowBox[{ StyleBox["HWT2D", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{ RowBox[{"N", "[", "A", "]"}], ",", RowBox[{"NumIterations", "\[Rule]", "1"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]}], StyleBox[";", FontColor->GrayLevel[0]]}], "\[IndentingNewLine]", RowBox[{ StyleBox["WaveletDensityPlot", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"B", ",", RowBox[{"NumIterations", "\[Rule]", "1"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]}], "Input", CellChangeTimes->{{3.408566878234375*^9, 3.40856691609375*^9}, { 3.408567550921875*^9, 3.40856755121875*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Using IHWT2D", "Section", CellChangeTimes->{3.4086629409375*^9}], Cell["\<\ In the cell below, we compute the inverse transform of the image.\ \>", "Text"], Cell[BoxData[{ RowBox[{ RowBox[{"B", " ", "=", " ", RowBox[{ StyleBox["HWT2D", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{ RowBox[{"N", "[", "A", "]"}], ",", RowBox[{"NumIterations", "\[Rule]", "1"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]}], StyleBox[";", FontColor->GrayLevel[0]]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ StyleBox["WaveletDensityPlot", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"B", ",", RowBox[{"NumIterations", "\[Rule]", "1"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"origA", " ", "=", " ", RowBox[{ StyleBox["IHWT2D", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"B", ",", RowBox[{"NumIterations", "\[Rule]", "1"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]}], StyleBox[";", FontColor->GrayLevel[0]]}], "\[IndentingNewLine]", RowBox[{ StyleBox["ImagePlot", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox["origA", FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]}], "Input", CellChangeTimes->{{3.408566943140625*^9, 3.408567037125*^9}, { 3.4085675475*^9, 3.408567547765625*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Iterating the Process", "Section"], Cell[TextData[{ "Just as with the one-dimensional HWT, we can iterate the two-dimensional \ HWT. In this case, the ", StyleBox["HWT2D", FontColor->RGBColor[1, 0, 0]], " is applied the approximation (blur) portion of the transform.\n\n", StyleBox["Warning: ", FontWeight->"Bold", FontColor->RGBColor[1, 0, 0]], " Make sure to know the maximum amount of iterations you can compute before \ proceeding!! You can use ImageList to display the maximum number of \ iterations that can be performed on each of the included images." }], "Text", CellChangeTimes->{{3.4085670735*^9, 3.408567136625*^9}, {3.40856718575*^9, 3.408567207765625*^9}}], Cell[BoxData[ RowBox[{"ImageList", "[", RowBox[{"ImageType", "\[Rule]", "GrayScale"}], "]"}]], "Input", CellChangeTimes->{{3.408567143453125*^9, 3.4085671571875*^9}, { 3.408567211015625*^9, 3.40856721875*^9}, {3.40856754371875*^9, 3.408567544046875*^9}}], Cell["\<\ Here we compute four iterations of the Haar wavelet transformation.\ \>", "Text", CellChangeTimes->{{3.408567230140625*^9, 3.40856724346875*^9}}], Cell[BoxData[{ StyleBox[ RowBox[{ RowBox[{"its", "=", "4"}], ";"}], FontColor->GrayLevel[0]], "\[IndentingNewLine]", RowBox[{ RowBox[{"B", " ", "=", StyleBox[" ", FontColor->RGBColor[0.501961, 0, 0]], RowBox[{ StyleBox["HWT2D", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"A", ",", RowBox[{"NumIterations", "\[Rule]", "its"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]}], StyleBox[";", FontColor->GrayLevel[0]]}], "\[IndentingNewLine]", RowBox[{ StyleBox["WaveletDensityPlot", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"B", ",", RowBox[{"NumIterations", "\[Rule]", "its"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]}], "Input", CellChangeTimes->{ 3.40856730640625*^9, {3.40856747234375*^9, 3.40856747884375*^9}, { 3.408567541140625*^9, 3.40856754146875*^9}, {3.40866311125*^9, 3.408663112921875*^9}}], Cell["\<\ You can plot various portions of the transform. Here is the vertical portion \ of the third iteration.\ \>", "Text", CellChangeTimes->{{3.408567350859375*^9, 3.408567360421875*^9}}], Cell[BoxData[ RowBox[{ StyleBox["WaveletDensityPlot", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"B", ",", RowBox[{"NumIterations", "\[Rule]", "its"}], ",", RowBox[{"Iteration", "\[Rule]", "3"}], ",", RowBox[{"Region", "\[Rule]", "Vertical"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]], "Input", CellChangeTimes->{{3.408567320671875*^9, 3.40856736390625*^9}, { 3.408567539078125*^9, 3.40856753934375*^9}}], Cell["Here is the horizontal portion of the first iteration.", "Text", CellChangeTimes->{{3.40856736571875*^9, 3.40856737515625*^9}}], Cell[BoxData[ RowBox[{ StyleBox["WaveletDensityPlot", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"B", ",", RowBox[{"NumIterations", "\[Rule]", "its"}], ",", RowBox[{"Iteration", "\[Rule]", "1"}], ",", RowBox[{"Region", "\[Rule]", "Horizontal"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]], "Input", CellChangeTimes->{{3.408567320671875*^9, 3.40856736390625*^9}, 3.408567398203125*^9, {3.408567536875*^9, 3.40856753715625*^9}}], Cell["Here is the blur.", "Text", CellChangeTimes->{{3.40856740109375*^9, 3.408567403453125*^9}}], Cell[BoxData[ RowBox[{ StyleBox["WaveletDensityPlot", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"B", ",", RowBox[{"NumIterations", "\[Rule]", "its"}], ",", RowBox[{"Region", "\[Rule]", "Blur"}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]], "Input", CellChangeTimes->{{3.408567320671875*^9, 3.40856736390625*^9}, { 3.408567398203125*^9, 3.40856741353125*^9}, {3.4085675345625*^9, 3.408567534875*^9}}], Cell["We can \"blow up\" the blur.", "Text"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"{", RowBox[{"rows", ",", "cols"}], "}"}], "=", RowBox[{"Dimensions", "[", "A", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ StyleBox["WaveletDensityPlot", FontColor->RGBColor[1, 0, 0]], StyleBox["[", FontColor->GrayLevel[0]], StyleBox[ RowBox[{"B", ",", RowBox[{"NumIterations", "\[Rule]", "its"}], ",", RowBox[{"Region", "\[Rule]", "Blur"}], ",", RowBox[{"ImageSize", "\[Rule]", RowBox[{"rows", "/", "2"}]}]}], FontColor->GrayLevel[0]], StyleBox["]", FontColor->GrayLevel[0]]}]}], "Input", CellChangeTimes->{{3.40856751325*^9, 3.40856753228125*^9}, 3.408663273203125*^9}] }, 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, 34, 0, 73, "Title"], Cell[627, 25, 247, 6, 69, "Subsubtitle"], Cell[CellGroupData[{ Cell[899, 35, 28, 0, 75, "Section"], Cell[930, 37, 112, 3, 29, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[1079, 45, 30, 0, 75, "Section"], Cell[1112, 47, 1259, 28, 119, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[2408, 80, 82, 1, 75, "Section"], Cell[2493, 83, 239, 4, 41, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[2769, 92, 66, 0, 75, "Section"], Cell[2838, 94, 546, 14, 65, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[3421, 113, 147, 2, 75, "Section"], Cell[3571, 117, 360, 10, 47, "Text"], Cell[3934, 129, 267, 6, 41, "Input"], Cell[4204, 137, 226, 6, 29, "Text"], Cell[4433, 145, 224, 5, 41, "Input"], Cell[4660, 152, 310, 9, 29, "Text"], Cell[4973, 163, 307, 8, 41, "Input"], Cell[5283, 173, 407, 10, 47, "Text"], Cell[5693, 185, 402, 11, 62, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[6132, 201, 110, 1, 75, "Section"], Cell[6245, 204, 205, 4, 29, "Text"], Cell[6453, 210, 433, 12, 62, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[6923, 227, 72, 1, 75, "Section"], Cell[6998, 230, 226, 4, 29, "Text"], Cell[7227, 236, 905, 31, 62, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[8169, 272, 71, 1, 75, "Section"], Cell[8243, 275, 89, 2, 29, "Text"], Cell[8335, 279, 1554, 55, 122, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[9926, 339, 40, 0, 75, "Section"], Cell[9969, 341, 651, 14, 101, "Text"], Cell[10623, 357, 264, 5, 41, "Input"], Cell[10890, 364, 156, 3, 29, "Text"], Cell[11049, 369, 1070, 36, 82, "Input"], Cell[12122, 407, 193, 4, 29, "Text"], Cell[12318, 413, 524, 15, 41, "Input"], Cell[12845, 430, 134, 1, 29, "Text"], Cell[12982, 433, 546, 15, 41, "Input"], Cell[13531, 450, 98, 1, 29, "Text"], Cell[13632, 453, 515, 15, 41, "Input"], Cell[14150, 470, 44, 0, 29, "Text"], Cell[14197, 472, 686, 21, 62, "Input"] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)