(************** Content-type: application/mathematica ************** CreatedBy='Mathematica 5.2' Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible application, such as Mathematica, MathReader or Publicon. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. *******************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 16240, 488]*) (*NotebookOutlinePosition[ 16884, 510]*) (* CellTagsIndexPosition[ 16840, 506]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Haar Transform 2D", "Subtitle"], Cell["\<\ Patrick J. Van Fleet Minicourse #5, Joint Mathematics Meetings New Orleans, LA\ \>", "Subsubtitle"], Cell["Objective", "Section"], Cell[CellGroupData[{ Cell["\<\ In this notebook, we will explore the two-dimensional discrete Haar wavelet \ transform.\ \>", "Subsubtitle"], Cell["Conventions", "Section"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "This notebook uses the package ", StyleBox["WaveletFunctions", FontColor->RGBColor[0.501961, 0, 0]], " (written by Patrick Van Fleet). All commands from the WaveletFunctions \ library will be denoted in ", StyleBox["maroon", FontColor->RGBColor[0.501961, 0, 0]], ". Help is available for almost every command in ", StyleBox["WaveletFunctions", FontColor->RGBColor[0.501961, 0, 0]], ". Click on Help and then Help Browser (or Shift F1). Next click the \ Add-ons & Links tab. Scroll down until you find ", StyleBox["WaveletFunctions", FontColor->RGBColor[0.501961, 0, 0]], ". 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\nValues that can be changed by the user are defined using ", StyleBox["blue", FontColor->RGBColor[0, 0, 1]], ".\n\nComments are useful within cells of code. Any code enclosed by (* \ *) is a comment and ignored by the ", StyleBox["Mathematica", FontSlant->"Italic"], " kernel." }], "Subsubtitle"], Cell[CellGroupData[{ Cell["Load WaveletFunctions", "Section"], Cell[BoxData[ \(\(\(<< WaveletFunctions`WaveletFunctions`\)\(\[IndentingNewLine]\) \)\)], "Input"] }, Open ]], Cell["Spelling Off", "Section"] }, Open ]], Cell[CellGroupData[{ Cell["\<\ This turns off the annoying error messages you get when the spelling of two \ variable names is close.\ \>", "Subsubtitle"], Cell[BoxData[{ \(\(Off[General::spell];\)\), "\[IndentingNewLine]", \(\(Off[General::spell1];\)\)}], "Input"], Cell["Two-Dimensional Discrete Haar Transform Modules", "Section"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "\nWe will use the 2D modules from ", StyleBox["WaveletFunctions", FontColor->RGBColor[0.501961, 0, 0]], " to compute Haar Transforms of matrices. The modules are ", StyleBox["WT2D", FontColor->RGBColor[0.501961, 0, 0]], " and ", StyleBox["IWT2D", FontColor->RGBColor[0.501961, 0, 0]], ". Both modules require three arguments. The first is the input matrix. \ The second is {1/2, 1/2}, {1, 1}, for ", StyleBox["WT2D", FontColor->RGBColor[0.501961, 0, 0]], ", ", StyleBox["IWT2D", FontColor->RGBColor[0.501961, 0, 0]], ", respectively. The last argument is the number of iterations." }], "Subsubtitle"], Cell["Locating Images", "Section"] }, Open ]], Cell[CellGroupData[{ Cell["\<\ If you have access to the internet, then use the imgdir variable that is \ listed for the internet. Else, use the imgdir for images already stored on \ your computer. If you have your own image, create a url/folder location as \ the imgdir variable.\ \>", "Subsubtitle"], Cell[BoxData[ RowBox[{\( (*\ This\ variable\ is\ the\ location\ of\ images\ on\ the\ \ \(\(web\)\(.\)\)\ *) \), "\[IndentingNewLine]", RowBox[{ StyleBox[\(imgdir = \ "\";\), FontColor->RGBColor[0, 0, 1]], "\[IndentingNewLine]", "\[IndentingNewLine]", \( (*\ This\ variable\ is\ the\ location\ of\ images\ on\ the\ local\ \ \(\(computer\)\(.\)\)\ *) \), "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ StyleBox["imgdir", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox["=", FontColor->RGBColor[0, 0, 1]], StyleBox[" ", FontColor->RGBColor[0, 0, 1]], StyleBox[\($BaseDirectory <> "\<\\Applications\\Images\\\>"\), FontColor->RGBColor[0, 0, 1]]}], StyleBox[";", FontColor->RGBColor[0, 0, 1]]}], " ", "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", \( (*\ You\ can\ create\ your\ own\ version\ of\ imgdir\ \ \(\(below\)\(.\)\)\ *) \), "\[IndentingNewLine]", RowBox[{"(*", " ", StyleBox[\(\(\(imgdir\)\(\ \)\(=\)\)\ ;\), FontColor->RGBColor[0, 0, 1]], " ", "*)"}], "\[IndentingNewLine]"}]}]], "Input"], Cell["Available Images", "Section"] }, Open ]], Cell[CellGroupData[{ Cell["\<\ Here is a list of images for use with this notebook. Surprisingly cartoons \ work really well! Some images work better than others. Uncomment one of the \ images. You can also add your own image!\ \>", "Subsubtitle"], Cell[BoxData[ RowBox[{ RowBox[{"(*", " ", StyleBox[\(image\ = \ "\";\), FontColor->RGBColor[0, 0, 1]], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ StyleBox[\(image = \ "\";\), FontColor->RGBColor[0, 0, 1]], "\[IndentingNewLine]", RowBox[{"(*", " ", StyleBox[\(image\ = \ "\";\), FontColor->RGBColor[0, 0, 1]], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", StyleBox[\(image\ = \ "\";\), FontColor->RGBColor[0, 0, 1]], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", StyleBox[\(image\ = \ "\";\), FontColor->RGBColor[0, 0, 1]], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", StyleBox[\(image = "\";\), FontColor->RGBColor[0, 0, 1]], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", StyleBox[\(image\ = \ "\";\), FontColor->RGBColor[0, 0, 1]], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", StyleBox[\(image\ = \ "\";\), FontColor->RGBColor[0, 0, 1]], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", StyleBox[\(\(\(image\)\(\ \)\(=\)\)\ ;\), FontColor->RGBColor[0, 0, 1]], " ", "*)"}]}]}]], "Input"], Cell["Loading and Plotting the Image", "Section"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "To load and plot an image, use ", StyleBox["ReadImage", FontColor->RGBColor[0.501961, 0, 0]], " and ", StyleBox["ImagePlot", FontColor->RGBColor[0.501961, 0, 0]], " from ", StyleBox["WaveletFunctions", FontColor->RGBColor[0.501961, 0, 0]], ". The ", StyleBox["ReadImage", FontColor->RGBColor[0.501961, 0, 0]], " function has two optional arguments. You can print information using ", StyleBox["PrintInfo", FontColor->RGBColor[0.501961, 0, 0]], " regarding the image (dimensions and whether the image was color or gray \ scale). You can also use ", StyleBox["PowersOfTwo", FontColor->RGBColor[0.501961, 0, 0]], " to chop rows/columns off the bottom/right to make the dimensions \ divisible by ", Cell[BoxData[ \(2\^i\)]], ".\n\n", StyleBox["Warning:", FontWeight->"Bold", FontColor->RGBColor[1, 0, 0]], " If you use your own image, make sure to use the ", StyleBox["PrintInfo", FontColor->RGBColor[0.501961, 0, 0]], " option. If the image is read as a color image (even though it looks gray \ scale), then uncomment the line below ", StyleBox["ReadImage", FontColor->RGBColor[0.501961, 0, 0]], " before processing it with ", StyleBox["WT2D", FontColor->RGBColor[0.501961, 0, 0]], "." }], "Subsubtitle"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"A", "=", StyleBox[\(ReadImage[imgdir <> image, PrintInfo \[Rule] True]\), FontColor->RGBColor[0.501961, 0, 0]]}], StyleBox[";", FontColor->RGBColor[0.501961, 0, 0]]}], "\[IndentingNewLine]", \( (*\ If\ your\ image\ was\ processed\ as\ a\ color\ image, \ uncomment\ the\ line\ below\ to\ convert\ \(\(it\)\(.\)\)\ *) \)}], "\ \[IndentingNewLine]", RowBox[{\( (*\ \(A\ = \ Total[A]/3;\)\ *) \)}]}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "The dimensions of the image below will be divisible by ", Cell[BoxData[ \(2\^6\)]], "." }], "Subsubtitle"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"A", "=", StyleBox[\(ReadImage[imgdir <> image, PrintInfo \[Rule] True, PowersOfTwo \[Rule] 6]\), FontColor->RGBColor[0.501961, 0, 0]]}], StyleBox[";", FontColor->RGBColor[0.501961, 0, 0]]}], "\[IndentingNewLine]", \( (*\ If\ your\ image\ was\ processed\ as\ a\ color\ image, \ uncomment\ the\ line\ below\ to\ convert\ \(\(it\)\(.\)\)\ *) \)}], "\ \[IndentingNewLine]", RowBox[{\( (*\ \(A\ = \ Total[A]/3;\)\ *) \)}]}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["Plotting images is really easy!", "Subsubtitle"], Cell[BoxData[ StyleBox[\(ImagePlot[A];\), FontColor->RGBColor[0.501961, 0, 0]]], "Input"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "You can add the ", StyleBox["LinearScaling", FontColor->RGBColor[0.501961, 0, 0]], " option. This maps the minimum value of the image to 0 and the maximum \ value of the image to 255. Try this on stooges.gif." }], "Subsubtitle"], Cell[BoxData[ StyleBox[\(ImagePlot[A, LinearScaling \[Rule] True];\), FontColor->RGBColor[0.501961, 0, 0]]], "Input"], Cell["Using WT2D", "Section"] }, Open ]], Cell[CellGroupData[{ Cell["\<\ In the cell below, we compute and plot the two-dimensional HWT of image A. \ {.5, .5} is used instead of {1/2, 1/2} to speed up computation.\ \>", "Subsubtitle"], Cell[BoxData[{ RowBox[{ RowBox[{"B", " ", "=", " ", StyleBox[\(WT2D[A, { .5, .5}, NumIterations \[Rule] 1]\), FontColor->RGBColor[0.501961, 0, 0]]}], StyleBox[";", FontColor->RGBColor[0.501961, 0, 0]]}], "\[IndentingNewLine]", StyleBox[\(WaveletDensityPlot[B, NumIterations \[Rule] 1, DivideLines \[Rule] True];\), FontColor->RGBColor[0.501961, 0, 0]]}], "Input"], Cell["Using IWT2D", "Section"] }, Open ]], Cell[CellGroupData[{ Cell["\<\ In the cell below, we compute the inverse transform of the image.\ \>", "Subsubtitle"], Cell[BoxData[{ RowBox[{ RowBox[{"B", " ", "=", " ", StyleBox[\(WT2D[A, { .5, .5}, NumIterations \[Rule] 1]\), FontColor->RGBColor[0.501961, 0, 0]]}], StyleBox[";", FontColor->RGBColor[0.501961, 0, 0]]}], "\[IndentingNewLine]", RowBox[{ StyleBox[\(WaveletDensityPlot[B, NumIterations \[Rule] 1, DivideLines \[Rule] True];\), FontColor->RGBColor[0.501961, 0, 0]], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"origA", " ", "=", " ", StyleBox[\(IWT2D[B, {1. , 1. }, NumIterations \[Rule] 1]\), FontColor->RGBColor[0.501961, 0, 0]]}], StyleBox[";", FontColor->RGBColor[0.501961, 0, 0]]}], "\[IndentingNewLine]", StyleBox[\(ImagePlot[origA];\), FontColor->RGBColor[0.501961, 0, 0]]}], "Input"], Cell["Iterating the Process", "Section"] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Just as with the one-dimensional HWT, we can iterate the two-dimensional \ HWT. In this case, the ", StyleBox["WT2D", FontColor->RGBColor[0.501961, 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!! ", StyleBox["WT2D", FontColor->RGBColor[0.501961, 0, 0]], " doesn't check (yet!) if the number of iterations divides the dimensions \ of A.\n\nHere are some maximum iteration numbers for our image list:\n\n", StyleBox["File", FontWeight->"Bold"], "\t\t\t\t", StyleBox["Max Iterations", FontWeight->"Bold"], "\nbeatles.png\t\t\t\t2\ncalvin_hobbes_gray.jpg\t\t5\nfingerprint.gif\t\t\t\ \t7\ngarfield_gray.jpg\t\t\t3\nmoonsurface.png\t\t\t3\t\nsnoopy_gray.jpg\t\t\t\ 1\nspockkirkmccoy.png\t\t\t3\nstooges.gif\t\t\t\t5" }], "Subsubtitle"], Cell[BoxData[{ StyleBox[\(its = 4;\), FontColor->RGBColor[0, 0, 1]], "\[IndentingNewLine]", RowBox[{ RowBox[{"B", " ", "=", StyleBox[" ", FontColor->RGBColor[0.501961, 0, 0]], StyleBox[\(WT2D[A, { .5, .5}, NumIterations \[Rule] its]\), FontColor->RGBColor[0.501961, 0, 0]]}], StyleBox[";", FontColor->RGBColor[0.501961, 0, 0]]}], "\[IndentingNewLine]", StyleBox[\(WaveletDensityPlot[B, NumIterations \[Rule] its, DivideLines \[Rule] True];\), FontColor->RGBColor[0.501961, 0, 0]]}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["You can plot various portions of the transform.", "Subsubtitle"], Cell[BoxData[{ RowBox[{ StyleBox[\(WaveletDensityPlot[B, NumIterations \[Rule] its, DivideLines \[Rule] True, Iteration \[Rule] 3, Region \[Rule] Vertical];\), FontColor->RGBColor[0.501961, 0, 0]], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{ StyleBox[\(WaveletDensityPlot[B, NumIterations \[Rule] its, DivideLines \[Rule] True, Iteration \[Rule] 1, Region \[Rule] Horizontal];\), FontColor->RGBColor[0.501961, 0, 0]], "\[IndentingNewLine]"}], "\[IndentingNewLine]", StyleBox[\(WaveletDensityPlot[B, NumIterations \[Rule] its, DivideLines \[Rule] True, Region \[Rule] Blur];\), FontColor->RGBColor[0.501961, 0, 0]]}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["We can \"blow up\" the blur.", "Subsubtitle"], Cell[BoxData[{\({rows, cols} = Dimensions[A];\), "\[IndentingNewLine]", StyleBox[\(WaveletDensityPlot[B, NumIterations \[Rule] its, DivideLines \[Rule] True, Region \[Rule] Blur, ImageSize \[Rule] rows];\), FontColor->RGBColor[0.501961, 0, 0]]}], "Input"] }, Open ]] }, Open ]] }, FrontEndVersion->"5.2 for Microsoft Windows", ScreenRectangle->{{0, 1024}, {0, 695}}, WindowSize->{1016, 651}, WindowMargins->{{0, Automatic}, {Automatic, 0}} ] (******************************************************************* Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. *******************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1776, 53, 37, 0, 51, "Subtitle"], Cell[1816, 55, 109, 4, 70, "Subsubtitle"], Cell[1928, 61, 28, 0, 73, "Section"], Cell[CellGroupData[{ Cell[1981, 65, 119, 3, 30, "Subsubtitle"], Cell[2103, 70, 30, 0, 73, "Section"] }, Open ]], Cell[CellGroupData[{ Cell[2170, 75, 1184, 28, 172, "Subsubtitle"], Cell[CellGroupData[{ Cell[3379, 107, 40, 0, 73, "Section"], Cell[3422, 109, 106, 2, 50, "Input"] }, Open ]], Cell[3543, 114, 31, 0, 73, "Section"] }, Open ]], Cell[CellGroupData[{ Cell[3611, 119, 133, 3, 30, "Subsubtitle"], Cell[3747, 124, 118, 2, 50, "Input"], Cell[3868, 128, 66, 0, 73, "Section"] }, Open ]], Cell[CellGroupData[{ Cell[3971, 133, 664, 18, 90, "Subsubtitle"], Cell[4638, 153, 34, 0, 73, "Section"] }, Open ]], Cell[CellGroupData[{ Cell[4709, 158, 282, 5, 50, "Subsubtitle"], Cell[4994, 165, 1450, 33, 190, "Input"], Cell[6447, 200, 35, 0, 73, "Section"] }, Open ]], Cell[CellGroupData[{ Cell[6519, 205, 230, 4, 50, "Subsubtitle"], Cell[6752, 211, 1528, 34, 190, "Input"], Cell[8283, 247, 49, 0, 73, "Section"] }, Open ]], Cell[CellGroupData[{ Cell[8369, 252, 1321, 39, 131, "Subsubtitle"], Cell[9693, 293, 538, 12, 70, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[10268, 310, 135, 5, 30, "Subsubtitle"], Cell[10406, 317, 587, 14, 70, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[11030, 336, 54, 0, 30, "Subsubtitle"], Cell[11087, 338, 99, 2, 30, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[11223, 345, 257, 6, 50, "Subsubtitle"], Cell[11483, 353, 127, 2, 30, "Input"], Cell[11613, 357, 29, 0, 73, "Section"] }, Open ]], Cell[CellGroupData[{ Cell[11679, 362, 172, 3, 50, "Subsubtitle"], Cell[11854, 367, 430, 9, 50, "Input"], Cell[12287, 378, 30, 0, 73, "Section"] }, Open ]], Cell[CellGroupData[{ Cell[12354, 383, 96, 2, 30, "Subsubtitle"], Cell[12453, 387, 848, 19, 110, "Input"], Cell[13304, 408, 40, 0, 73, "Section"] }, Open ]], Cell[CellGroupData[{ Cell[13381, 413, 988, 23, 352, "Subsubtitle"], Cell[14372, 438, 588, 13, 70, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[14997, 456, 70, 0, 30, "Subsubtitle"], Cell[15070, 458, 763, 15, 110, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[15870, 478, 51, 0, 30, "Subsubtitle"], Cell[15924, 480, 288, 4, 50, "Input"] }, Open ]] }, Open ]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)