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.

Import["name.ext"]import graphics from the file in a format deduced from the file name
Import["file","format"]import graphics in the specified format
ImportString["string","format"]import graphics from a string

Importing graphics and sounds.

This imports an image stored in JPEG format.
In[1]:=
Click for copyable input
Out[1]=
This shows an array of four copies of the image.
In[2]:=
Click for copyable input
Out[2]=
This imports a sound stored in a WAV file.
In[3]:=
Click for copyable input
Out[3]=

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.

Graphics[primitives,opts]resolution-independent graphics
Image[data,opts]resolution-dependent bitmap images
{graphics1,graphics2,...}animated graphics
Sound[SampledSoundList[data,r]]sounds

Structures of expressions returned by Import.

This shows the overall structure of the graphics object imported above.
In[4]:=
Click for copyable input
Out[4]//Shallow=
This extracts the array of pixel values used.
In[5]:=
Click for copyable input
Here are the dimensions of the array.
In[6]:=
Click for copyable input
Out[6]=
This shows the distribution of pixel values.
In[7]:=
Click for copyable input
Out[7]=
This shows a transformed version of the image.
In[8]:=
Click for copyable input
Out[8]=
New to Mathematica? Find your learning path »
Have a question? Ask support »