The Mathematica Journal
Departments
Feature Articles
Columns
New Products
New Publications
Classifieds
Calendar
News Bulletins
Mailbox
Letters
Write Us
About the Journal
Staff and Contributors
Submissions
Subscriptions
Advertising
Back Issues
Home
Download this Issue

Introduction

While it has always been possible to do image manipulation in Mathematica, several new features in Version 4.0 make it quick, easy, and fun.

First you need to import an image. Fortunately, Version 4.0 includes a powerful Import 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.

[Graphics:../Images/index_gr_1.gif]

Given just the file name, Mathematica looks in several directories (the one containing Mathematica itself, your home directory, etc.). If the file is not located in one of these standard locations, you may need to include the full path name to locate the file. For example, owners of the electronic edition of [1] can use the following command to load a picture of a very cute puppy (used throughout this article).

[Graphics:../Images/index_gr_2.gif]

Or, the following command can be used to import any file on your disk (you will get an open-file dialog box in which you can choose the file to import).

[Graphics:../Images/index_gr_3.gif]

The Import command returns an ordinary Mathematica expression containing a representation of the data in the file. The exact format of the expression of course depends on the type of data in the file. In the case of an image, the expression is a bit too long to print out, but it has the overall structure:


Graphics[
  Raster[data,pixelrange,valuerange,
    ColorFunction->RGBColor],
  AspectRatio->Automatic]

where data is a two-dimensional list of triplets (red, green, blue), pixelrange represents the dimensions of the image, and valuerange represents the minimum and maximum values of the numbers in the data. This expression is intentionally constructed in such a way that the standard Show function will reproduce the image, as seen here.

[Graphics:../Images/index_gr_4.gif]

[Graphics:../Images/index_gr_5.gif]

When Import is used to import image files, the structure will always be similar to what is described above, but some details may vary depending on the image format. For example, if the image is a grayscale image the ColorFunction option will be set to GrayLevel. If the image is an index color image, the ColorFunction will be a large expression containing the color lookup table for the image.

In this article, we're going to assume you're using an RGB color image such as a JPEG.


Converted by Mathematica      April 21, 2000

[Article Index] [Next Page]