PPM (.ppm)

Background & Context

    • 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 & Export

  • Import["file.ppm"] imports a PPM file, returning an Image object.
  • If multiple images are present in a PPM file, Import returns the first of the images.
  • Import["file.ppm",elem] imports the specified element from a PPM file.
  • The import format can be specified with Import["file","PPM"] or Import["file",{"PPM",elem,}].
  • 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 Wolfram Language 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.
  • See the following reference pages for full general information:
  • Import, Exportimport from or export to a file
    CloudImport, CloudExportimport from or export to a cloud object
    ImportString, ExportStringimport from or export to a string
    ImportByteArray, ExportByteArrayimport from or export to a byte array

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

Import Elements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Summary"summary of the file
    "Rules"list of rules for all available elements
  • 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 "Image" element for PPM files.
  • Advanced Import elements:
  • "BitDepth"bits used to represent each color channel in the file
    "Channels"the number of color channels used in the file
    "ColorSpace"color space of the image
    "DataType"data type used for storing pixel elements
    "ImageSize"raster dimensions
    "Summary"summary of the file

Options

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

Examples

Basic Examples  (1)

Import a PPM file: