(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 4.0, MathReader 4.0, or any compatible application. 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[ 5815, 189]*) (*NotebookOutlinePosition[ 6471, 212]*) (* CellTagsIndexPosition[ 6427, 208]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell[TextData[{ "Image manipulation with ", StyleBox["Mathematica", FontSlant->"Italic"], " " }], "Subtitle"], Cell[TextData[{ "To do image manipulation, the first thing you need is to import the image. \ Fortunately, ", StyleBox["Mathematica", FontSlant->"Italic"], " 4 includes a powerful ", StyleBox["Import", "Input"], " command that is able to handle a wide range of image formats \ automatically. In general, you just give it the name of the file you want to \ import and it figures out the format automatically. For example, the \ following command imports a JPEG image of a very cute puppy (assuming of \ course that you have a file with this name):" }], "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(SetDirectory["\"]\)], "Input"], Cell[BoxData[ \("C:\\My Documents\\IMS\\Numerics Tutorial\\Image Manipulation"\)], \ "Output"] }, Open ]], Cell[BoxData[ \(\(puppyImage = Import["\"];\)\)], "Input"], Cell[BoxData[ \(\(Show[puppyImage];\)\)], "Input"], Cell["\<\ The basic part of the image is just imported as numeric data. Without going \ into details, I can define\ \>", "Text"], Cell[BoxData[ \(\(ImageData[image_]\ := \ image[\([1, 1]\)];\)\)], "Input"], Cell["Then, ", "Text"], Cell[BoxData[ \(Dimensions[ImageData[puppyImage]]\)], "Input"], Cell["\<\ tells me the image has data for three colors at 484x445 (= 215380) points. \ \ \>", "Text"], Cell[BoxData[ \(Part[ImageData[puppyImage], 1, 1]\)], "Input"], Cell["\<\ Shows what the data looks like for a single point. In fact, the data \ consists of integers between 0 and 255.\ \>", "Text"], Cell["\<\ The first thing I will show you how to do is quite basic, but will be useful \ for the examples I show you, it is selecting a subimage to view or \ manipulate. As is typical for tasks that I might do repeatedly, I will \ define a function to do it.\ \>", "Text"], Cell[BoxData[ \(ImagePart[image_, xp_, \ yp_]\ := \ \[IndentingNewLine]Module[{newimage\ = \ image}, \[IndentingNewLine]newimage[\([1, 1]\)]\ = \ Take[ImageData[newimage], yp, xp]; \[IndentingNewLine]Show[ newimage]]\)], "Input"], Cell[BoxData[ \(\(ball\ = \ ImagePart[puppyImage, {234, 313}, {1, 80}];\)\)], "Input"], Cell[BoxData[ \(\(pup\ = \ ImagePart[puppyImage, {130, 290}, {200, 360}];\)\)], "Input"], Cell[BoxData[ \(\(lefteye\ = \ ImagePart[pup, {92, 110}, {89, 107}];\)\)], "Input"], Cell[TextData[{ "Since the data is represented in ", StyleBox["Mathematica", FontSlant->"Italic"], " as lists of numbers, you can use any ", StyleBox["Mathematica", FontSlant->"Italic"], " command which is appropriate for such." }], "Text"], Cell[BoxData[ \(\(Block[{newimage\ = \ pup}, \[IndentingNewLine]newimage[\([1, 1]\)]\ = \ Transpose[ImageData[pup]]; \[IndentingNewLine]Show[ newimage]];\)\)], "Input"], Cell["\<\ In fact, once you realize that an image is just a particular way of viewing a \ (particular type) of dataset, the possibilities become endless for \ manipulating the image. In todays presentation, I will demonstrate a few of \ the possibilities:\ \>", "Text"], Cell[TextData[{ "When the colors are combined to produce a ", ButtonBox["grayscale image", ButtonData:>{"Grayscale.nb", None}, ButtonStyle->"Hyperlink"], ", the data becomes a simple matrix and it is easy to work with." }], "Text"], Cell[TextData[{ "One thing you can do in ", StyleBox["Mathematica", FontSlant->"Italic"], " that standard image processing programs cannot is work with a ", ButtonBox["continuous", ButtonData:>{"Continuous.nb", None}, ButtonStyle->"Hyperlink"], " function representation." }], "Text"], Cell[TextData[{ "The idea of ", ButtonBox["mapping", ButtonData:>{"Maps.nb", None}, ButtonStyle->"Hyperlink"], " the image leads to some interesting ways of visualizing numerical data." }], "Text"] }, Open ]] }, FrontEndVersion->"4.0 for Microsoft Windows", ScreenRectangle->{{0, 1024}, {0, 695}}, WindowSize->{496, 599}, WindowMargins->{{Automatic, 125}, {Automatic, 28}} ] (*********************************************************************** 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[1739, 51, 119, 5, 65, "Subtitle"], Cell[1861, 58, 577, 12, 129, "Text"], Cell[CellGroupData[{ Cell[2463, 74, 111, 2, 70, "Input"], Cell[2577, 78, 98, 2, 29, "Output"] }, Open ]], Cell[2690, 83, 76, 1, 30, "Input"], Cell[2769, 86, 54, 1, 30, "Input"], Cell[2826, 89, 129, 3, 52, "Text"], Cell[2958, 94, 80, 1, 30, "Input"], Cell[3041, 97, 22, 0, 33, "Text"], Cell[3066, 99, 66, 1, 30, "Input"], Cell[3135, 102, 102, 3, 33, "Text"], Cell[3240, 107, 66, 1, 30, "Input"], Cell[3309, 110, 135, 3, 52, "Text"], Cell[3447, 115, 273, 5, 71, "Text"], Cell[3723, 122, 279, 5, 90, "Input"], Cell[4005, 129, 91, 1, 30, "Input"], Cell[4099, 132, 93, 1, 30, "Input"], Cell[4195, 135, 88, 1, 30, "Input"], Cell[4286, 138, 258, 8, 52, "Text"], Cell[4547, 148, 208, 4, 70, "Input"], Cell[4758, 154, 270, 5, 71, "Text"], Cell[5031, 161, 245, 6, 52, "Text"], Cell[5279, 169, 306, 9, 52, "Text"], Cell[5588, 180, 211, 6, 33, "Text"] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)