Skip to main content

Read and write Netpbm files

Project description

Netpbmfile is a Python library to read and write image files in the Netpbm format as specified at

The following Netpbm and Portable FloatMap formats are supported:

  • PBM (bi-level)
  • PGM (grayscale)
  • PPM (color)
  • PAM (arbitrary)
  • XV thumbnail (RGB332, read-only)
  • PF (float32 RGB, read-only)
  • Pf (float32 grayscale, read-only)

No gamma correction is performed. Only one image per file is supported.

Author:Christoph Gohlke
Organization:Laboratory for Fluorescence Dynamics, University of California, Irvine
License:BSD 3-Clause



Fix reading tightly packed P1 format and ASCII data with inline comments. Remove support for Python 2.7 and 3.5. Update copyright.
Move into netpbmfile package.
Support Portable FloatMaps. Style fixes.
Use ‘fromdata’ classmethod to initialize from data. Support ‘with’ statement. Scale RGB images to maxval for display. Make keyword arguments explicit. Support numpy 1.10.


Save a numpy array to a Netpbm file in grayscale format:

>>> data = numpy.array([[0, 1], [65534, 65535]], dtype='uint16')
>>> imwrite('_tmp.pgm', data)

Read the image data from a Netpbm file as numpy array:

>>> image = imread('_tmp.pgm')
>>> assert numpy.all(image == data)

Access meta and image data in a Netpbm file:

>>> with NetpbmFile('_tmp.pgm') as pgm:
...     pgm.axes
...     pgm.shape
...     pgm.dtype
...     pgm.maxval
...     pgm.magicnum
...     image = pgm.asarray()
(2, 2)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for netpbmfile, version 2020.1.1
Filename, size File type Python version Upload date Hashes
Filename, size netpbmfile-2020.1.1-py3-none-any.whl (9.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size netpbmfile-2020.1.1.tar.gz (7.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page