This is documentation for Mathematica 4, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
Wolfram Research, Inc.

Exporting Graphics and SoundsContents

2.9.20 Importing Graphics and Sounds

Mathematica allows you not only to export graphics and sounds, but also to import them. With Import you can read graphics and sounds in a wide variety of formats, and bring them into Mathematica as Mathematica expressions.

Importing graphics and sounds.

This imports an image stored in JPEG format.

In[3]:= g = Import["ocelot.jpg"]

Out[3]=

Here is the image.

In[4]:= Show[g]

Out[4]=

This shows an array of four copies of the image.

In[5]:= Show[GraphicsArray[{{g, g}, {g, g}}]]

Out[5]=

Import yields expressions with different structures depending on the type of data it reads. Typically you will need to know the structure if you want to manipulate the data that is returned.

Structures of expressions returned by Import.

This shows the overall structure of the graphics object imported above.

In[6]:= Shallow[InputForm[g]]

Out[6]//Shallow=

This extracts the array of pixel values used.

In[7]:= d = g[[1, 1]] ;

Here are the dimensions of the array.

In[8]:= Dimensions[d]

Out[8]=

This shows the distribution of pixel values.

In[9]:= ListPlot[Sort[Flatten[d]]]

Out[9]=

This shows a transformed version of the image.

In[10]:= Show[Graphics[Raster[d^2 / Max[d^2]]],

AspectRatio->Automatic]

Out[10]=

Exporting Graphics and SoundsContents