PPM (.ppm)

MIME type: image/x-portable-pixmap
PPM color raster image format.
Member of the Portable family of image formats.
Related to PBM and PGM.
Implements a subset of the PNM format.
Native format of the Netpbm graphics software package.
Primarily used as an intermediate file format on Unix systems.
PPM is an acronym for Portable Pixel Map.
ASCII or Binary format.
Stores raster images as 8-bit or 16-bit RGB data.
Developed in 1988 as part of the Pbmplus package.
  • Import and Export fully support the PPM format.
  • Export creates binary PPM files.
  • If multiple images are present in a PPM file, Import returns the first of the images.

Import and ExportImport and Export

  • Import["file.ppm"] imports a PPM file, returning an Image object.
  • Export["file.ppm", expr] exports an image, graphics or any other expression as a raster image to PPM.
  • Export by default generates binary PPM files.
  • When exporting Mathematica graphics or arbitrary expressions to PPM, the resulting image has the same raster size as its displayed form.
  • Image objects are by default exported at their raster size.
  • Because PPM is a raster image format, all fonts are rasterized on export.
  • Import["file.ppm", elem] imports the specified element from a PPM file.
  • Import["file.ppm", {elem, suba, subb, ...}] imports a subelement.
  • Import["file.ppm", {{elem1, elem2, ...}}] imports multiple elements.
  • The import format can be specified with Import["file", "PPM"] or Import["file", {"PPM", elem, ...}].
  • Export["file.ppm", expr, elem] creates a PPM file by treating expr as specifying element elem.
  • Export["file.ppm", {expr1, expr2, ...}, {{elem1, elem2, ...}}] treats each as specifying the corresponding .
  • Export["file.ppm", expr, opt1->val1, ...] exports expr with the specified option elements taken to have the specified values.
  • Export["file.ppm", {elem1->expr1, elem2->expr2, ...}, "Rules"] uses rules to specify the elements to be exported.
  • See the reference pages for full general information on Import and Export.
  • ImportString and ExportString support the PPM format.

Notebook InterfaceNotebook Interface

  • In the notebook front end, Insert ► Picture and the Open menu allow import of a PPM file into a cell.
  • Save Selection As exports the selected part of a notebook as a PPM file.

ElementsElements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Rules"full list of rules for each element and option
    "Options"list of rules for options, properties, and settings
  • Data representation elements:
  • "Data"array of RGB triples
    "Graphics"Graphics object representing an image
    "GrayLevels"array of normalized gray-level values
    "Image"raster image, given as an Image object
    "RGBColorArray"array of RGBColor objects
  • Import and Export by default use the element for PPM files.
  • Advanced Import elements:
  • "BitDepth"bits used to represent each color channel in the file
    "ImageSize"raster dimensions

OptionsOptions

  • General options:
  • ImageSizeAutomaticoverall image size
    "DataType"Automaticdata type used for storing pixel elements
  • Export option:
  • "ImageTopOrientation"Toporientation of the exported image
  • Detailed property:
  • "ColorSpace"RGBColorcolor space of the image

ExamplesExamplesopen allclose all

Basic Examples (1)Basic Examples (1)

Import a PPM example file:

In[1]:=
Click for copyable input
Out[1]=

Import several meta-information elements:

In[2]:=
Click for copyable input
Out[2]=
New in 4 | Last modified in 7
New to Mathematica? Find your learning path »
Have a question? Ask support »