Skip to main content

images-into-array

Build Status GitHub license PyPI - Python Version PyPI - Wheel PyPI Conda Version Anaconda-Server Badge Anaconda-Server Badge Conda Platforms Conda Recipe

Downloads

images-into-array is a Python package for loading multiple images from a directory, resizing them to a common size, optionally converting them into different OpenCV color spaces, and returning them as NumPy arrays.

The package was originally developed as part of research work on masked face detection and employee access control.

Features

  • Load multiple images from a directory.
  • Resize images to a specified height and width.
  • Return images as NumPy arrays.
  • Support grayscale and multiple OpenCV color spaces.
  • Preserve the original public function names for backwards compatibility.
  • Simple API suitable for computer-vision and machine-learning workflows.

Installation

PyPI

pip install images-into-array

Conda

conda install -c conda-forge images-into-array

Usage

The image directory and image dimensions should be supplied to the functions.

from images_into_array import images

images_path = "/path/to/images"
image_height = 32
image_width = 32

image_array = images(images_path, image_height, image_width)

print(image_array.shape)

For example, if the directory contains 100 RGB/BGR images and the requested size is 32 x 32, the returned array will normally have a shape similar to:

(100, 32, 32, 3)

For grayscale images:

(100, 32, 32)

Note: OpenCV reads color images in BGR order by default. The package therefore uses OpenCV's BGR-based color conversion operations.

Supported Functions

Function OpenCV conversion Description


images() None Load normal color images rgb_gray() BGR2GRAY Convert images to grayscale rgb_lab() BGR2Lab Convert images to Lab rgb_hsv() BGR2HSV Convert images to HSV rgb_ycrcb() BGR2YCrCb Convert images to YCrCb rgb_hls() BGR2HLS Convert images to HLS rgb_luv() BGR2Luv Convert images to Luv

The rgb_* function names are retained for compatibility with earlier versions of the package.

Examples

Normal Images

from images_into_array import images

images_path = "/path/to/images"
image_height = 32
image_width = 32

data = images(images_path, image_height, image_width)

Grayscale

from images_into_array import rgb_gray

data = rgb_gray(images_path, image_height, image_width)

Lab

from images_into_array import rgb_lab

data = rgb_lab(images_path, image_height, image_width)

HSV

from images_into_array import rgb_hsv

data = rgb_hsv(images_path, image_height, image_width)

YCrCb

from images_into_array import rgb_ycrcb

data = rgb_ycrcb(images_path, image_height, image_width)

HLS

from images_into_array import rgb_hls

data = rgb_hls(images_path, image_height, image_width)

Luv

from images_into_array import rgb_luv

data = rgb_luv(images_path, image_height, image_width)

Requirements

The package uses:

  • Python
  • NumPy
  • OpenCV
  • tqdm

Install the main dependencies with:

pip install numpy opencv-python tqdm

The package does not require the third-party shuffle package. Python provides random.shuffle as part of the standard library.

Important Notes

Image dimensions

OpenCV's cv2.resize() expects the size in:

(width, height)

Therefore, even though the API accepts:

image_height
image_width

the resize operation should use:

cv2.resize(image, (image_width, image_height))

Invalid or unreadable images

If an image cannot be read by OpenCV, cv2.imread() may return None. Production code should handle such files rather than attempting to resize them.

Reproducibility

If the image order is shuffled for machine-learning experiments, consider using a fixed random seed when reproducible experiments are required.

Research

This package was developed in connection with research on masked face detection and selected employee access to workplaces.

Published Research

Mandal, S., Saha, M. & Chatterji, B.N.
Masked Face Detection and Selected Employee Access to Workplaces: A Step Towards Coronavirus Prevention.

Journal of The Institution of Engineers (India): Series B, 104, 1353--1368 (2023).

DOI: https://doi.org/10.1007/s40031-023-00945-5

The research presents a CCTV-based approach for detecting masked faces and identifying selected employees, using a two-tier convolutional neural network.

Source Code

GitHub repository:

https://github.com/sujitmandal/images-into-array

PyPI:

https://pypi.org/project/images-into-array/

License

This project is licensed under the MIT License.

See the LICENSE file for details.

Author

Sujit Mandal

GitHub: https://github.com/sujitmandal

Citation

If you use this package or the associated research in academic work, please cite the published paper:

Mandal, S., Saha, M. & Chatterji, B.N. Masked Face Detection and Selected Employee Access to Workplaces: A Step Towards Coronavirus Prevention. Journal of The Institution of Engineers (India): Series B 104, 1353–1368 (2023). https://doi.org/10.1007/s40031-023-00945-5

Metadata

Release files for images-into-array 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for images-into-array 3.0.0
File Size Uploaded
images_into_array-3.0.0.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for images-into-array 3.0.0
File Interpreter ABI Platform
images_into_array-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.2 kB

Release files / images_into_array-3.0.0.tar.gz

Download URL images_into_array-3.0.0.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
12016e1d79ff1933858599c0704e466e05fd64b080a18c5fec5739fa5e339e04
BLAKE2b-256 checksum
How to use checksums
853075587a6b39343d71467c48cd3dfd7b3860c66255e835b94ea492d64dda8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.9

Release files / images_into_array-3.0.0-py3-none-any.whl

Download URL images_into_array-3.0.0-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
96709d605deb4bcb9192b10fd4eb9f18ae13cb4adc289e9dc53585c5a9b2e5b2
BLAKE2b-256 checksum
How to use checksums
3ea80a770cf584c5957b1f42c0ff3931a10915a58a3ec386dca8a305bd4a6ef5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.9

Release history Release notifications | RSS feed

3.0.1

2 release files

This release

3.0.0 This release

2 release files

2.0.7

2 release files

2.0.6

2 release files

2.0.5

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.10.1

2 release files

1.10.0

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page