Skip to main content

Utilities to get arrays & histograms from grayscale images and build images from arrays.

Project description

image_array_and_histogram

CI PyPI - Version PyPI - Python Version

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 if as_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_array or get_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

image_array_and_histogram-1.1.7.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

image_array_and_histogram-1.1.7-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file image_array_and_histogram-1.1.7.tar.gz.

File metadata

File hashes

Hashes for image_array_and_histogram-1.1.7.tar.gz
Algorithm Hash digest
SHA256 f89119ee8d738628a03170c794a4cbb89a89f4566e15be50ee3ace19b17e4e37
MD5 bdc84a4bcf81a0c6c91ee208cec623a5
BLAKE2b-256 cda6a939639ff43e24e07a692be0c67fe4b2c943db6c4477bbb088918f65c32b

See more details on using hashes here.

Provenance

The following attestation bundles were made for image_array_and_histogram-1.1.7.tar.gz:

Publisher: python-publish.yml on rishi-chauhan/my-packages

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file image_array_and_histogram-1.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for image_array_and_histogram-1.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 0857fe8be95981f9cf00d77901cc7abcc6eb57b8eb7736158acd7f88d41720fc
MD5 4de29c28f4d658892621d3b7b69041bf
BLAKE2b-256 e443368ed72a78fb8f6a53e4dddcb6a357747286ab58049b2d7c759f64b269ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for image_array_and_histogram-1.1.7-py3-none-any.whl:

Publisher: python-publish.yml on rishi-chauhan/my-packages

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page