The Mathematica Journal
Feature Articles
New Products
New Publications
News Bulletins
Write Us
About the Journal
Staff and Contributors
Back Issues
Download this Issue


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.


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).


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).


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:


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.



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]