Skip to main content

imgarray (Python)

This stores 1D and 2D numpy arrays as png images. As a method of storage, not visualization (use pillow for that).

Q: Why would you ever want that?

  • It’s somewhat, though not extremely, space-efficient.

  • Saving and loading PNGs is supported by many languages, so all you need to do is port this library.

  • Results look kind of funny, nothing too interesting though.

  • Because you can.

Example

https://raw.githubusercontent.com/mverleg/imgarray/master/demo.png

Installation

This package requires numpy and pillow. They will be installed automatically if you install using pip:

pip install imgarray

Usage

Usage is very simple, there are only two functions:

from imgarray import save_array_img, load_array_img
data = randn((500, 500)).astype(int16)
save_array_img(data, path)
data2 = load_array_img(path)

You can check out demo.py or the tests for more (not a lot more to be fair, it’s a simple tool).

Notes

  • 1D arrays will be returned as 2D arrays with one unit dimension, because images are 2D.

  • It works with most numpy data types (specifically, the ones that use a number of bytes which is a power of 2).

  • If you remove metadata from the PNG, the file only loads correctly if the data was float64, and you’ll also get a warning.

  • If the data has more or less than 4 bytes per value, the height of the image is scaled to match. So array shape and image shape are similar but not necessarily identical.

Usage & contributions

Revised BSD License; at your own risk, you can mostly do whatever you want with this code, just don’t use my name for promotion and do keep the license file.

Pull requests are welcome, especially with unit tests. Due to the great importance of this library, maintenance is not going to be high-priority.

Metadata

Release files for imgarray 1.0

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

Source distribution (sdist)

Source distribution for imgarray 1.0
File Size Uploaded
imgarray-1.0.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for imgarray 1.0
File Interpreter ABI Platform
imgarray-1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 11.3 kB

Release files / imgarray-1.0.tar.gz

Download URL imgarray-1.0.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
482287fc6ffdb3c0917761bd43679bcd39c5476536268ddc7266f29b644937df
BLAKE2b-256 checksum
How to use checksums
1a0a761ffe5476516cd0952f975ca6b80add38534d6234514ccc4faab73a08f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / imgarray-1.0-py2.py3-none-any.whl

Download URL imgarray-1.0-py2.py3-none-any.whl
Size 6.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
d6943f79d83d142c98ac182545483231a3a6aeee3b11822ea68535670e6970f9
BLAKE2b-256 checksum
How to use checksums
bf063a338011b059ebe9f31acaa793f21e960a148d652daa013e1b75daf38c28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0 This release

2 release files

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