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.
- 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.
pip install images-into-arrayconda install -c conda-forge images-into-arrayThe 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.
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.
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)from images_into_array import rgb_gray
data = rgb_gray(images_path, image_height, image_width)from images_into_array import rgb_lab
data = rgb_lab(images_path, image_height, image_width)from images_into_array import rgb_hsv
data = rgb_hsv(images_path, image_height, image_width)from images_into_array import rgb_ycrcb
data = rgb_ycrcb(images_path, image_height, image_width)from images_into_array import rgb_hls
data = rgb_hls(images_path, image_height, image_width)from images_into_array import rgb_luv
data = rgb_luv(images_path, image_height, image_width)The package uses:
- Python
- NumPy
- OpenCV
- tqdm
Install the main dependencies with:
pip install numpy opencv-python tqdmThe package does not require the third-party shuffle package.
Python provides random.shuffle as part of the standard library.
OpenCV's cv2.resize() expects the size in:
(width, height)Therefore, even though the API accepts:
image_height
image_widththe resize operation should use:
cv2.resize(image, (image_width, image_height))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.
If the image order is shuffled for machine-learning experiments, consider using a fixed random seed when reproducible experiments are required.
This package was developed in connection with research on masked face detection and selected employee access to workplaces.
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.
GitHub repository:
https://github.com/sujitmandal/images-into-array
PyPI:
https://pypi.org/project/images-into-array/
This project is licensed under the MIT License.
See the LICENSE file for details.
Sujit Mandal
GitHub: https://github.com/sujitmandal
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