Skip to main content

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 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

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.1.tar.gz (6.0 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.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for image_array_and_histogram-1.1.1.tar.gz
Algorithm Hash digest
SHA256 384b780abcbda2dc8adfe7a40060754446c291a3d04d92232f634416b525be60
MD5 2bd76c1b9711335efe538f8e42dd2686
BLAKE2b-256 e0f98caa37e93017e6928907b94be94da7630ce4d053e416adc9d199897693e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for image_array_and_histogram-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 99e0b996eb95058773299d909220b91fb050d478982687761792ad05f5676bc2
MD5 3b61053241eb67fb7fb6236f517abf14
BLAKE2b-256 4b47c8b6588235ddabdbebdbd5d2b5533448d9acc5a2d33c360707db7f9d5414

See more details on using hashes here.

Supported by

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