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.8.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.8-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for image_array_and_histogram-1.1.8.tar.gz
Algorithm Hash digest
SHA256 43e7aba976eadcee5c816a86831fc5011a2c8bbbbdc7ac8b55d304acd2746573
MD5 e67b0bd043a6ef325e02a0a350f36b05
BLAKE2b-256 0987b2b19bcda186023b0c061c1829af0a055ea7a47a3ee5b309b70ae6d6bce5

See more details on using hashes here.

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

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.8-py3-none-any.whl.

File metadata

File hashes

Hashes for image_array_and_histogram-1.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 9c3154d73054d87ba7dd3ba6c622941a4b663e4bb6ff53d56fb918767d93fb83
MD5 7bb2b2b2b2fb6486fa4c9a78c6f1b34e
BLAKE2b-256 71c78281975713f915080d2f1379111c59a58b47bb0fc86ce78abf85fb378ee0

See more details on using hashes here.

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

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