Skip to main content

Read and write Netpbm files

Netpbmfile is a Python library to read and write image files in the Netpbm format as specified at http://netpbm.sourceforge.net/doc/.

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 grayscale, read-only)

  • PF (float32 RGB, read-only)

  • PF4 (float32 RGBA, read-only)

  • PGX (signed grayscale, read-only)

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

The PGX format is specified in ITU-T Rec. T.803.

Author:

Christoph Gohlke

Organization:

Laboratory for Fluorescence Dynamics, University of California, Irvine

License:

BSD 3-Clause

Version:

2022.2.2

Requirements

This release has been tested with the following requirements and dependencies (other versions may work):

Revisions

2022.2.2

Add type hints. Support reading PF4 RGBA FloatMaps. Drop support for Python 3.7 and numpy < 1.19 (NEP29).

2021.6.6

Fix unclosed file warnings. Support reading PGX JPEG2000 reference images.

2020.10.18

Disallow comments after last value in PNM headers.

2020.9.18

Remove support for Python 3.6 (NEP 29). Support os.PathLike file names.

2020.1.1

Fix reading tightly packed P1 format and ASCII data with inline comments. Remove support for Python 2.7 and 3.5. Update copyright.

2018.10.18

Move netpbmfile.py into netpbmfile package.

2018.02.18

Support reading Portable FloatMaps. Style fixes.

2016.02.24

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.

Examples

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()
'YX'
(2, 2)
dtype('>u2')
65535
b'P5'

To view the image stored in a Netpbm file from a command line, run python -m netpbmfile _tmp.pgm.

Metadata

Release files for netpbmfile 2022.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for netpbmfile 2022.2.2
File Size Uploaded
netpbmfile-2022.2.2.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for netpbmfile 2022.2.2
File Interpreter ABI Platform
netpbmfile-2022.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 20.3 kB

Release files / netpbmfile-2022.2.2.tar.gz

Download URL netpbmfile-2022.2.2.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
97dbfac500e03b61a02cc76c4ca8946fb5a6f0b229be6dfe55237107651e447b
BLAKE2b-256 checksum
How to use checksums
c3669452bee84d0c8a90d80d341e188511f1d892933946e1dfa31f4d5cf6dfd1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

Release files / netpbmfile-2022.2.2-py3-none-any.whl

Download URL netpbmfile-2022.2.2-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a8aeeb4ad0d79ee126537b6ac12a2142dec249c657c9adf9bc04795102638e3a
BLAKE2b-256 checksum
How to use checksums
1e6ab98d117024d67f0599dfefe061d179b978c4d0aa101acb124861abce986d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page