Python3 library for simple image operations either using OpenCV or Pillow.
pip install simple_image_ops
pip install git+https://github.com/waikato-datamining/simple-image-ops.git
The following I/O operations are available:
simops.load_file
- loads an image from disksimops.load_bytes
- loads an image from a bytes structuresimops.save_file
- saves an image to disksimops.save_bytes
- saves an images into a bytes structure
NB: the save_
methods allow specifying the JPEG quality via the
jpeg_quality
parameter.
The following image operations are available:
simops.flip
- flips the image left/right or top/bottomsimops.resize
- resizes the imagesimops.rotate
- rotates the image by 90/180/270 degrees counter-clockwise
These helper methods are available:
simops.numpy_available
- whether Numpy is availablesimops.opencv_available
- whether OpenCV is availablesimops.pillow_available
- whether Pillow is available
The following loads the images from disk, resizes it using explicit width/height, and saves it back to disk:
from simops import load_file, resize, save_file
img = load_file("input.jpg")
img_res = resize(img, width=800, height=600)
save_file(img_res, "output.jpg")
Here we load the image from bytes, resize it specifying only the width (therefore keeping the aspect ratio) and then turn it back into bytes (using JPEG format):
from simops import load_bytes, resize, save_bytes
data_in = ... # obtained from somewhere
img = load_bytes(data_in)
img_res = resize(img, width=1024)
data_out = save_bytes(img_res, "JPEG")