How to |
Import and Export Images
Of the many ways images can be loaded into a Mathematica
is the main method used to access image files on your local computer or at a remote location. The import and export of images are the most common first and last steps of practically any image processing computation.
Use the menu item or type a file path to import a local image file as an image object.
This example imports an image from the Mathematica
documentation directory ExampleData:
provides a general mechanism for naming and finding files that works on all systems.
to construct a complete path to a file on the local system:
By specifying the elements of an image for Import
, you can get useful information before loading it into the kernel. The file type is automatically deduced from the file name extension:
Return the size of the image:
Once you have imported the image, you can modify and analyze it. As a simple example, consider how the image changes appearance under different permutations of its color channels.
Separate the color channels:
Permute the channels in six different ways and form color images from each:
You can now save the six different images in your local file system by exporting them in any of the many supported file formats. In this example, the JPEG
format is used because it stores efficiently.
You can export to an existing directory or create a new directory from within Mathematica.
is used to create a directory in the local system's temporary storage area:
to construct a file name using a simple indexing scheme:
to iterate the naming of the files based on the indexing scheme:
Import one of the saved images to verify the save operation: