(* 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[ 15739, 553] NotebookOptionsPosition[ 13257, 468] NotebookOutlinePosition[ 13672, 486] CellTagsIndexPosition[ 13629, 483] WindowFrame->Normal ContainsDynamic->False*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["Transforming a Picture", "Title"], Cell["\<\ M. E. Mauel Columbia University\ \>", "Subsubtitle"], Cell[CellGroupData[{ Cell["Introduction", "Section"], Cell[TextData[{ "This notebook is only a guide-book to using ", StyleBox["Mathematica", FontSlant->"Italic"], ". We explore (without explanation) what happens when we use the built-in \ function ", StyleBox["Fourier[\[Ellipsis]]", FontWeight->"Bold"], ". " }], "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Reading a Photo", "Section"], Cell[BoxData[ RowBox[{"SetDirectory", "[", "\"\<~/Desktop/\>\"", "]"}]], "Input", CellLabel->"In[1]:="], Cell[BoxData[ RowBox[{ RowBox[{"g1", " ", "=", " ", RowBox[{"Import", "[", "\"\\"", "]"}]}], ";"}]], "Input", CellLabel->"In[2]:="], Cell[BoxData[ RowBox[{ RowBox[{"g1Data", " ", "=", " ", RowBox[{"Part", "[", RowBox[{"g1", ",", "1", ",", "1"}], "]"}]}], ";"}]], "Input", CellLabel->"In[3]:="], Cell[BoxData[ RowBox[{"Dimensions", "[", "g1Data", "]"}]], "Input", CellLabel->"In[4]:="], Cell[BoxData[ RowBox[{"ListDensityPlot", "[", RowBox[{"g1Data", ",", RowBox[{"Mesh", "\[Rule]", "False"}], ",", RowBox[{"AspectRatio", "\[Rule]", "Automatic"}]}], "]"}]], "Input", CellLabel->"In[5]:="] }, Closed]], Cell[CellGroupData[{ Cell["Fourier", "Section"], Cell[BoxData[ RowBox[{"?", "Fourier"}]], "Input", CellLabel->"In[6]:="], Cell[BoxData[ RowBox[{ RowBox[{"f1", " ", "=", " ", RowBox[{"Fourier", "[", "g1Data", "]"}]}], ";"}]], "Input", CellLabel->"In[7]:="], Cell[BoxData[ RowBox[{"Dimensions", "[", "f1", "]"}]], "Input", CellLabel->"In[8]:="], Cell[BoxData[ RowBox[{"f1", " ", "//", " ", "Shallow"}]], "Input", CellLabel->"In[9]:="], Cell[BoxData[ RowBox[{"ListDensityPlot", "[", RowBox[{ RowBox[{"Re", "[", "f1", "]"}], ",", RowBox[{"Mesh", "\[Rule]", "False"}], ",", RowBox[{"AspectRatio", "\[Rule]", "Automatic"}], ",", RowBox[{"ColorFunction", "\[Rule]", "Hue"}]}], "]"}]], "Input", CellLabel->"In[10]:="], Cell[BoxData[ RowBox[{"ListDensityPlot", "[", RowBox[{ RowBox[{"Im", "[", "f1", "]"}], ",", RowBox[{"Mesh", "\[Rule]", "False"}], ",", RowBox[{"AspectRatio", "\[Rule]", "Automatic"}], ",", RowBox[{"ColorFunction", "\[Rule]", "Hue"}]}], "]"}]], "Input", CellLabel->"In[11]:="], Cell[BoxData[ RowBox[{"ListDensityPlot", "[", RowBox[{ RowBox[{"Abs", "[", "f1", "]"}], ",", RowBox[{"Mesh", "\[Rule]", "False"}], ",", RowBox[{"AspectRatio", "\[Rule]", "Automatic"}], ",", RowBox[{"ColorFunction", "\[Rule]", "Hue"}]}], "]"}]], "Input", CellLabel->"In[21]:="], Cell[BoxData[ RowBox[{"ListDensityPlot", "[", RowBox[{ RowBox[{"Arg", "[", "f1", "]"}], ",", RowBox[{"Mesh", "\[Rule]", "False"}], ",", RowBox[{"AspectRatio", "\[Rule]", "Automatic"}], ",", RowBox[{"ColorFunction", "\[Rule]", "Hue"}]}], "]"}]], "Input", CellLabel->"In[22]:="] }, Closed]], Cell[CellGroupData[{ Cell["Symmetry", "Section"], Cell[TextData[{ "Our original photo contained 290 x 200 pixels. Our transform also contains \ 290 x 200 numbers, but each number is ", StyleBox["complex.", FontSlant->"Italic"], " For each of the original (real) data, two numbers appeared! Please don't \ be fooled. We did not create information. The Fourier transform of real data \ contains an important symmetry property. The information is duplicated." }], "Text"], Cell[BoxData[ RowBox[{ RowBox[{"{", RowBox[{"dim1", ",", " ", "dim2"}], "}"}], " ", "=", " ", RowBox[{"Dimensions", "[", "f1", "]"}]}]], "Input", CellLabel->"In[12]:="], Cell[BoxData[ RowBox[{ RowBox[{"Conjugate", "[", RowBox[{"f1", "\[LeftDoubleBracket]", RowBox[{"2", ",", "2"}], "\[RightDoubleBracket]"}], "]"}], " ", "\[Equal]", " ", RowBox[{"f1", "\[LeftDoubleBracket]", RowBox[{"dim1", ",", "dim2"}], "\[RightDoubleBracket]"}]}]], "Input", CellLabel->"In[14]:="], Cell[BoxData[ RowBox[{ RowBox[{"symmetryQ", "[", RowBox[{"i_", ",", "j_"}], "]"}], " ", ":=", " ", RowBox[{ RowBox[{"Conjugate", "[", RowBox[{"f1", "\[LeftDoubleBracket]", RowBox[{ RowBox[{"1", "+", "i"}], ",", RowBox[{"1", "+", "j"}]}], "\[RightDoubleBracket]"}], "]"}], " ", "\[Equal]", " ", RowBox[{"f1", "\[LeftDoubleBracket]", RowBox[{ RowBox[{"dim1", "-", RowBox[{"(", RowBox[{"i", "-", "1"}], ")"}]}], ",", RowBox[{"dim2", " ", "-", " ", RowBox[{"(", RowBox[{"j", "-", "1"}], ")"}]}]}], "\[RightDoubleBracket]"}]}]}]], "Input", CellLabel->"In[15]:="], Cell[BoxData[ RowBox[{"Table", "[", RowBox[{ RowBox[{"symmetryQ", "[", RowBox[{ RowBox[{"RandomInteger", "[", RowBox[{"{", RowBox[{"1", ",", FractionBox["dim1", "2"]}], "}"}], "]"}], ",", RowBox[{"RandomInteger", "[", RowBox[{"{", RowBox[{"1", ",", FractionBox["dim2", "2"]}], "}"}], "]"}]}], "]"}], ",", RowBox[{"{", "10", "}"}]}], "]"}]], "Input", CellLabel->"In[16]:="] }, Closed]], Cell[CellGroupData[{ Cell["Inverse Fourier Transform", "Section"], Cell[BoxData[ RowBox[{ RowBox[{"g2Data", " ", "=", " ", RowBox[{ RowBox[{"InverseFourier", "[", "f1", "]"}], " ", "//", " ", "Chop"}]}], ";"}]], "Input", CellLabel->"In[20]:="], Cell[BoxData[ RowBox[{"ListDensityPlot", "[", RowBox[{"g2Data", ",", RowBox[{"Mesh", "\[Rule]", "False"}], ",", RowBox[{"AspectRatio", "\[Rule]", "Automatic"}]}], "]"}]], "Input", CellLabel->"In[21]:="] }, Closed]], Cell[CellGroupData[{ Cell["Filtering (Low-Pass)", "Section"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"lowPass", "[", "fraction_", "]"}], "[", "transform_List", "]"}], ":=", " ", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"dim1", ",", "dim2", ",", "filter"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{"dim1", ",", "dim2"}], "}"}], " ", "=", " ", RowBox[{"Dimensions", "[", "transform", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"filter", " ", "=", " ", RowBox[{"Table", "[", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"fraction", " ", RowBox[{"dim1", "/", "2"}]}], " ", "<", " ", "i", " ", "<", " ", RowBox[{ RowBox[{"(", RowBox[{"1", "-", RowBox[{"fraction", "/", "2"}]}], ")"}], " ", "dim1"}]}], " ", "&&", " ", RowBox[{ RowBox[{"fraction", " ", RowBox[{"dim2", "/", "2"}]}], " ", "<", " ", "j", " ", "<", " ", RowBox[{ RowBox[{"(", RowBox[{"1", " ", "-", " ", RowBox[{"fraction", "/", "2"}]}], ")"}], " ", "dim2"}]}]}], ",", " ", "0", ",", " ", "1"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "dim1"}], "}"}], ",", RowBox[{"{", RowBox[{"j", ",", "1", ",", "dim2"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"ListDensityPlot", "[", RowBox[{"filter", ",", RowBox[{"Mesh", "\[Rule]", " ", "False"}], ",", " ", RowBox[{"AspectRatio", "\[Rule]", " ", "Automatic"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"filter", " ", "*", " ", "transform"}]}]}], "]"}]}]], "Input", CellLabel->"In[45]:="], Cell[BoxData[ RowBox[{ RowBox[{"f2", " ", "=", " ", RowBox[{ RowBox[{"lowPass", "[", "0.5", "]"}], "[", "f1", "]"}]}], ";"}]], "Input",\ CellLabel->"In[46]:="], Cell[BoxData[ RowBox[{"ListDensityPlot", "[", RowBox[{ RowBox[{"Abs", "[", "f2", "]"}], ",", RowBox[{"Mesh", "\[Rule]", "False"}], ",", RowBox[{"AspectRatio", "\[Rule]", "Automatic"}], ",", RowBox[{"ColorFunction", "\[Rule]", "Hue"}]}], "]"}]], "Input", CellLabel->"In[47]:="], Cell[BoxData[ RowBox[{ RowBox[{"g3Data", " ", "=", " ", RowBox[{ RowBox[{"InverseFourier", "[", "f2", "]"}], " ", "//", " ", "Re"}]}], ";"}]], "Input", CellLabel->"In[48]:="], Cell[BoxData[ RowBox[{"ListDensityPlot", "[", RowBox[{"g3Data", ",", RowBox[{"Mesh", "\[Rule]", "False"}], ",", RowBox[{"AspectRatio", "\[Rule]", "Automatic"}]}], "]"}]], "Input", CellLabel->"In[49]:="] }, Closed]], Cell[CellGroupData[{ Cell["Filtering (High-Pass)", "Section"], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"highPass", "[", "fraction_", "]"}], "[", "transform_List", "]"}], ":=", " ", RowBox[{"Module", "[", RowBox[{ RowBox[{"{", RowBox[{"dim1", ",", "dim2", ",", "filter"}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"{", RowBox[{"dim1", ",", "dim2"}], "}"}], " ", "=", " ", RowBox[{"Dimensions", "[", "transform", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"filter", " ", "=", " ", RowBox[{"Table", "[", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"fraction", " ", RowBox[{"dim1", "/", "2"}]}], " ", "<", " ", "i", " ", "<", " ", RowBox[{ RowBox[{"(", RowBox[{"1", "-", RowBox[{"fraction", "/", "2"}]}], ")"}], " ", "dim1"}]}], " ", "&&", " ", RowBox[{ RowBox[{"fraction", " ", RowBox[{"dim2", "/", "2"}]}], " ", "<", " ", "j", " ", "<", " ", RowBox[{ RowBox[{"(", RowBox[{"1", " ", "-", " ", RowBox[{"fraction", "/", "2"}]}], ")"}], " ", "dim2"}]}]}], ",", " ", "1", ",", " ", "0"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", "dim1"}], "}"}], ",", RowBox[{"{", RowBox[{"j", ",", "1", ",", "dim2"}], "}"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"ListDensityPlot", "[", RowBox[{"filter", ",", RowBox[{"Mesh", "\[Rule]", " ", "False"}], ",", " ", RowBox[{"AspectRatio", "\[Rule]", " ", "Automatic"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"filter", " ", "*", " ", "transform"}]}]}], "]"}]}]], "Input", CellLabel->"In[50]:="], Cell[BoxData[ RowBox[{ RowBox[{"f2", " ", "=", " ", RowBox[{ RowBox[{"highPass", "[", "0.5", "]"}], "[", "f1", "]"}]}], ";"}]], "Input",\ CellLabel->"In[51]:="], Cell[BoxData[ RowBox[{"ListDensityPlot", "[", RowBox[{ RowBox[{"Abs", "[", "f2", "]"}], ",", RowBox[{"Mesh", "\[Rule]", "False"}], ",", RowBox[{"AspectRatio", "\[Rule]", "Automatic"}], ",", RowBox[{"ColorFunction", "\[Rule]", "Hue"}]}], "]"}]], "Input", CellLabel->"In[52]:="], Cell[BoxData[ RowBox[{ RowBox[{"g3Data", " ", "=", " ", RowBox[{ RowBox[{"InverseFourier", "[", "f2", "]"}], " ", "//", " ", "Re"}]}], ";"}]], "Input", CellLabel->"In[53]:="], Cell[BoxData[ RowBox[{"ListDensityPlot", "[", RowBox[{"g3Data", ",", RowBox[{"Mesh", "\[Rule]", "False"}], ",", RowBox[{"AspectRatio", "\[Rule]", "Automatic"}]}], "]"}]], "Input", CellLabel->"In[54]:="] }, Closed]], Cell[CellGroupData[{ Cell["Filtering (Phase Only)", "Section"], Cell[BoxData[ RowBox[{ RowBox[{"gPhaseData", " ", "=", " ", RowBox[{ RowBox[{"InverseFourier", "[", RowBox[{"Exp", "[", RowBox[{"I", " ", RowBox[{"Arg", "[", "f1", "]"}]}], "]"}], "]"}], " ", "//", " ", "Re"}]}], ";"}]], "Input", CellLabel->"In[59]:="], Cell[BoxData[ RowBox[{"ListDensityPlot", "[", RowBox[{"gPhaseData", ",", RowBox[{"Mesh", "\[Rule]", "False"}], ",", RowBox[{"AspectRatio", "\[Rule]", "Automatic"}]}], "]"}]], "Input", CellLabel->"In[60]:="] }, Closed]], Cell[CellGroupData[{ Cell["Filtering (Amplitude Only)", "Section"], Cell[BoxData[ RowBox[{ RowBox[{"gAmpData", " ", "=", " ", RowBox[{ RowBox[{"InverseFourier", "[", RowBox[{"Abs", "[", "f1", "]"}], "]"}], " ", "//", " ", "Re"}]}], ";"}]], "Input", CellLabel->"In[61]:="], Cell[BoxData[ RowBox[{"ListDensityPlot", "[", RowBox[{"gAmpData", ",", RowBox[{"Mesh", "\[Rule]", "False"}], ",", RowBox[{"AspectRatio", "\[Rule]", "Automatic"}]}], "]"}]], "Input", CellLabel->"In[62]:="] }, Closed]], Cell[CellGroupData[{ Cell["Summary", "Section"], Cell[TextData[{ "This notebook illustrates how to import graphics into ", StyleBox["Mathematica ", FontSlant->"Italic"], "and how to use the built-in ", StyleBox["Fourier[\[Ellipsis]]", FontWeight->"Bold"], " transform to process and filter data." }], "Text"] }, Closed]] }, Open ]] }, WindowSize->{657, 899}, WindowMargins->{{13, Automatic}, {Automatic, 15}}, PrintingCopies->1, PrintingPageRange->{1, Automatic}, ShowSelection->True, FrontEndVersion->"6.0 for Mac OS X x86 (32-bit) (May 21, 2008)", StyleDefinitions->"TutorialBook.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[590, 23, 39, 0, 51, "Title"], Cell[632, 25, 62, 3, 41, "Subsubtitle"], Cell[CellGroupData[{ Cell[719, 32, 31, 0, 86, "Section"], Cell[753, 34, 277, 9, 48, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[1067, 48, 34, 0, 54, "Section"], Cell[1104, 50, 105, 2, 26, "Input"], Cell[1212, 54, 155, 4, 26, "Input"], Cell[1370, 60, 173, 5, 24, "Input"], Cell[1546, 67, 91, 2, 26, "Input"], Cell[1640, 71, 214, 5, 45, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[1891, 81, 26, 0, 54, "Section"], Cell[1920, 83, 73, 2, 26, "Input"], Cell[1996, 87, 141, 4, 26, "Input"], Cell[2140, 93, 87, 2, 26, "Input"], Cell[2230, 97, 90, 2, 26, "Input"], Cell[2323, 101, 295, 7, 45, "Input"], Cell[2621, 110, 295, 7, 45, "Input"], Cell[2919, 119, 296, 7, 45, "Input"], Cell[3218, 128, 296, 7, 45, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[3551, 140, 27, 0, 54, "Section"], Cell[3581, 142, 424, 8, 77, "Text"], Cell[4008, 152, 179, 5, 26, "Input"], Cell[4190, 159, 322, 8, 26, "Input"], Cell[4515, 169, 655, 20, 64, "Input"], Cell[5173, 191, 448, 14, 91, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[5658, 210, 44, 0, 54, "Section"], Cell[5705, 212, 191, 6, 26, "Input"], Cell[5899, 220, 215, 5, 24, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[6151, 230, 39, 0, 54, "Section"], Cell[6193, 232, 1865, 51, 207, "Input"], Cell[8061, 285, 172, 6, 24, "Input"], Cell[8236, 293, 296, 7, 45, "Input"], Cell[8535, 302, 189, 6, 26, "Input"], Cell[8727, 310, 215, 5, 45, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[8979, 320, 40, 0, 54, "Section"], Cell[9022, 322, 1866, 51, 207, "Input"], Cell[10891, 375, 173, 6, 26, "Input"], Cell[11067, 383, 296, 7, 45, "Input"], Cell[11366, 392, 189, 6, 26, "Input"], Cell[11558, 400, 215, 5, 45, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[11810, 410, 41, 0, 54, "Section"], Cell[11854, 412, 290, 9, 26, "Input"], Cell[12147, 423, 219, 5, 45, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[12403, 433, 45, 0, 54, "Section"], Cell[12451, 435, 224, 7, 26, "Input"], Cell[12678, 444, 217, 5, 45, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[12932, 454, 26, 0, 54, "Section"], Cell[12961, 456, 268, 8, 48, "Text"] }, Closed]] }, Open ]] } ] *) (* End of internal cache information *)