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 http://netpbm.sourceforge.net/doc/
The following Netpbm and related formats are supported:
PBM (Portable Bit Map): P1 (text) and P4 (binary)
PGM (Portable Gray Map): P2 (text) and P5 (binary)
PPM (Portable Pixel Map): P3 (text) and P6 (binary)
PNM (Portable Any Map): shorthand for PBM, PGM, and PPM collectively
PAM (Portable Arbitrary Map): P7, bilevel, gray, and rgb
PFM (Portable Float Map): Pf (gray), PF (rgb), and PF4 (rgba), read-only
PGX (Portable Graymap Signed): PG, signed grayscale, read-only
XV thumbnail: P7 332 (rgb332), read-only
No gamma correction is performed.
The PGX format is specified in ITU-T Rec. T.803.
- Author:
- License:
BSD 3-Clause
- Version:
2022.10.25
Quickstart
Install the netpbmfile package and all dependencies from the Python Package Index:
python -m pip install -U netpbmfile[all]
View image and metadata stored in a Netpbm file:
python -m oiffile file.ppm
See Examples for using the programming interface.
Source code and support are available on GitHub.
Requirements
This release has been tested with the following requirements and dependencies (other versions may work):
Revisions
2022.10.25
Read multi-image files.
Fix reading ASCII formats with trailing comments.
Fix writing maxval=1, depth=1 binary images.
Use tifffile.imshow for multi-image arrays if installed.
Change tupltypes to bytes according to specification (breaking).
2022.9.12
Allow space after token value in PAM.
Update metadata.
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=numpy.uint16) >>> imwrite('_tmp.pgm', data)
Read the image data from a Netpbm file as numpy array:
>>> image = imread('_tmp.pgm') >>> numpy.testing.assert_equal(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'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file netpbmfile-2022.10.25.tar.gz
.
File metadata
- Download URL: netpbmfile-2022.10.25.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cb2eebd94a507473d9b6d2427d382206c2dae9c8c3119f47da517165c49924d |
|
MD5 | 897ba3e3cc066aeb5a4abc901ffac0fe |
|
BLAKE2b-256 | 5842bb45b74faae803f704db4a5cf424afa0e46de477aa5b2e7aee7cd15404d6 |
File details
Details for the file netpbmfile-2022.10.25-py3-none-any.whl
.
File metadata
- Download URL: netpbmfile-2022.10.25-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 407638970334447b1e572cad7ffff40680cf0585f4b43ca43b53976c4a484287 |
|
MD5 | 917f0f9ca8acc24c6a2a7cba5b043f5b |
|
BLAKE2b-256 | ccd37226433d6b37688011c5eea851787b48d6722932fb4cbff2cafe1442e910 |