Skip to content

Repository files navigation

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

Package Link

Conda Package Link

images-into-array-feedstock

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

About

convert multiple images into array

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages