Utilities to get arrays & histograms from grayscale images and build images from arrays.
Project description
image_array_and_histogram
Utilities to convert images to NumPy arrays, compute grayscale histograms, and reconstruct images from arrays.
Version 1.1.0 introduces PEP-8 function names and fixes the historical axis
ordering bug. Arrays are now always shaped (height, width). The old camelCase
names are still available but deprecated.
Installation
$ pip install image-array-and-histogram
Functions (current API)
get_image_array(image, ensure_grayscale=True)– Return a 2D uint8 NumPy array (height, width) from a PIL image. Converts to grayscale by default.get_hist(image_or_array, as_density=False)– Return a 256-length list of counts (or probabilities ifas_density=True). Accepts either a PIL image or a NumPy/list array.array_to_image(arr, width=None, height=None)– Build a grayscale PIL image from a 1D or 2D array.
Deprecated aliases (will emit DeprecationWarning): getImageArray, getHist, getImageFromArray.
Quick Start
from PIL import Image
import numpy as np
from image_array_and_histogram import get_image_array, get_hist, array_to_image
# Load image and get array
img = Image.open('photo.jpg')
arr = get_image_array(img) # shape (H, W)
# Compute histogram
hist = get_hist(arr) # list of 256 counts
# Normalize histogram
hist_density = get_hist(arr, as_density=True)
# Create an image from a NumPy array
gradient = np.linspace(0, 255, 256, dtype=np.uint8).reshape(16, 16)
gradient_img = array_to_image(gradient)
gradient_img.save('gradient.png')
Notes
- If you pass a color image to
get_image_arrayorget_hist, it will be converted to grayscale (mode 'L'). - Histogram computation is vectorized with NumPy (
numpy.bincount) for speed. - For legacy behavior (<=1.0.x) the array shape used
(width, height). Adjust any downstream code if it relied on that ordering.
Testing
After cloning the repository:
pip install -e .[dev]
pytest -q
License
MIT
Project details
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file image_array_and_histogram-1.1.8.tar.gz.
File metadata
- Download URL: image_array_and_histogram-1.1.8.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43e7aba976eadcee5c816a86831fc5011a2c8bbbbdc7ac8b55d304acd2746573
|
|
| MD5 |
e67b0bd043a6ef325e02a0a350f36b05
|
|
| BLAKE2b-256 |
0987b2b19bcda186023b0c061c1829af0a055ea7a47a3ee5b309b70ae6d6bce5
|
Provenance
The following attestation bundles were made for image_array_and_histogram-1.1.8.tar.gz:
Publisher:
python-publish.yml on rishi-chauhan/my-packages
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
image_array_and_histogram-1.1.8.tar.gz -
Subject digest:
43e7aba976eadcee5c816a86831fc5011a2c8bbbbdc7ac8b55d304acd2746573 - Sigstore transparency entry: 930465945
- Sigstore integration time:
-
Permalink:
rishi-chauhan/my-packages@fb4cc6b211420e9e0f558999a42b30751a80b4ac -
Branch / Tag:
refs/tags/v1.1.8 - Owner: https://github.com/rishi-chauhan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@fb4cc6b211420e9e0f558999a42b30751a80b4ac -
Trigger Event:
push
-
Statement type:
File details
Details for the file image_array_and_histogram-1.1.8-py3-none-any.whl.
File metadata
- Download URL: image_array_and_histogram-1.1.8-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c3154d73054d87ba7dd3ba6c622941a4b663e4bb6ff53d56fb918767d93fb83
|
|
| MD5 |
7bb2b2b2b2fb6486fa4c9a78c6f1b34e
|
|
| BLAKE2b-256 |
71c78281975713f915080d2f1379111c59a58b47bb0fc86ce78abf85fb378ee0
|
Provenance
The following attestation bundles were made for image_array_and_histogram-1.1.8-py3-none-any.whl:
Publisher:
python-publish.yml on rishi-chauhan/my-packages
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
image_array_and_histogram-1.1.8-py3-none-any.whl -
Subject digest:
9c3154d73054d87ba7dd3ba6c622941a4b663e4bb6ff53d56fb918767d93fb83 - Sigstore transparency entry: 930465948
- Sigstore integration time:
-
Permalink:
rishi-chauhan/my-packages@fb4cc6b211420e9e0f558999a42b30751a80b4ac -
Branch / Tag:
refs/tags/v1.1.8 - Owner: https://github.com/rishi-chauhan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@fb4cc6b211420e9e0f558999a42b30751a80b4ac -
Trigger Event:
push
-
Statement type: