image-array-and-histogram


Nameimage-array-and-histogram JSON
Version 1.1.1 PyPI version JSON
download
home_pagehttps://github.com/rishi-chauhan/my-packages.git
SummaryUtilities to get arrays & histograms from grayscale images and build images from arrays.
upload_time2025-08-11 22:35:33
maintainerNone
docs_urlNone
authorRishi Raj Singh Chauhan
requires_python>=3.8
licenseMIT
keywords image histogram numpy pillow grayscale
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```sh
$ 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

```python
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:

```sh
pip install -e .[dev]
pytest -q
```

## License

MIT

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rishi-chauhan/my-packages.git",
    "name": "image-array-and-histogram",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "image, histogram, numpy, pillow, grayscale",
    "author": "Rishi Raj Singh Chauhan",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/e0/f9/8caa37e93017e6928907b94be94da7630ce4d053e416adc9d199897693e3/image_array_and_histogram-1.1.1.tar.gz",
    "platform": null,
    "description": "# image_array_and_histogram\n\nUtilities to convert images to NumPy arrays, compute grayscale histograms, and\nreconstruct images from arrays.\n\nVersion 1.1.0 introduces PEP-8 function names and fixes the historical axis\nordering bug. Arrays are now always shaped `(height, width)`. The old camelCase\nnames are still available but deprecated.\n\n## Installation\n\n```sh\n$ pip install image-array-and-histogram\n```\n\n## Functions (current API)\n\n- `get_image_array(image, ensure_grayscale=True)` \u2013 Return a 2D uint8 NumPy array (height, width) from a PIL image. Converts to grayscale by default.\n- `get_hist(image_or_array, as_density=False)` \u2013 Return a 256-length list of counts (or probabilities if `as_density=True`). Accepts either a PIL image or a NumPy/list array.\n- `array_to_image(arr, width=None, height=None)` \u2013 Build a grayscale PIL image from a 1D or 2D array.\n\nDeprecated aliases (will emit `DeprecationWarning`): `getImageArray`, `getHist`, `getImageFromArray`.\n\n## Quick Start\n\n```python\nfrom PIL import Image\nimport numpy as np\nfrom image_array_and_histogram import get_image_array, get_hist, array_to_image\n\n# Load image and get array\nimg = Image.open('photo.jpg')\narr = get_image_array(img)  # shape (H, W)\n\n# Compute histogram\nhist = get_hist(arr)  # list of 256 counts\n\n# Normalize histogram\nhist_density = get_hist(arr, as_density=True)\n\n# Create an image from a NumPy array\ngradient = np.linspace(0, 255, 256, dtype=np.uint8).reshape(16, 16)\ngradient_img = array_to_image(gradient)\ngradient_img.save('gradient.png')\n```\n\n## Notes\n\n- If you pass a color image to `get_image_array` or `get_hist`, it will be converted to grayscale (mode 'L').\n- Histogram computation is vectorized with NumPy (`numpy.bincount`) for speed.\n- For legacy behavior (<=1.0.x) the array shape used `(width, height)`. Adjust any downstream code if it relied on that ordering.\n\n## Testing\n\nAfter cloning the repository:\n\n```sh\npip install -e .[dev]\npytest -q\n```\n\n## License\n\nMIT\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Utilities to get arrays & histograms from grayscale images and build images from arrays.",
    "version": "1.1.1",
    "project_urls": {
        "Homepage": "https://github.com/rishi-chauhan/my-packages",
        "Issue Tracker": "https://github.com/rishi-chauhan/my-packages/issues"
    },
    "split_keywords": [
        "image",
        " histogram",
        " numpy",
        " pillow",
        " grayscale"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "4b47c8b6588235ddabdbebdbd5d2b5533448d9acc5a2d33c360707db7f9d5414",
                "md5": "3b61053241eb67fb7fb6236f517abf14",
                "sha256": "99e0b996eb95058773299d909220b91fb050d478982687761792ad05f5676bc2"
            },
            "downloads": -1,
            "filename": "image_array_and_histogram-1.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3b61053241eb67fb7fb6236f517abf14",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 6043,
            "upload_time": "2025-08-11T22:35:32",
            "upload_time_iso_8601": "2025-08-11T22:35:32.477532Z",
            "url": "https://files.pythonhosted.org/packages/4b/47/c8b6588235ddabdbebdbd5d2b5533448d9acc5a2d33c360707db7f9d5414/image_array_and_histogram-1.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e0f98caa37e93017e6928907b94be94da7630ce4d053e416adc9d199897693e3",
                "md5": "2bd76c1b9711335efe538f8e42dd2686",
                "sha256": "384b780abcbda2dc8adfe7a40060754446c291a3d04d92232f634416b525be60"
            },
            "downloads": -1,
            "filename": "image_array_and_histogram-1.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "2bd76c1b9711335efe538f8e42dd2686",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 6031,
            "upload_time": "2025-08-11T22:35:33",
            "upload_time_iso_8601": "2025-08-11T22:35:33.633096Z",
            "url": "https://files.pythonhosted.org/packages/e0/f9/8caa37e93017e6928907b94be94da7630ce4d053e416adc9d199897693e3/image_array_and_histogram-1.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-11 22:35:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rishi-chauhan",
    "github_project": "my-packages",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "image-array-and-histogram"
}
        
Elapsed time: 1.13179s