imutils: Image Processing Utility Functions

0.5.4 · maintenance · verified Mon Apr 13

imutils is a Python package providing a series of convenience functions to simplify basic image processing operations such as translation, rotation, resizing, skeletonization, displaying Matplotlib images, sorting contours, and detecting edges. It acts as a companion library to OpenCV, streamlining common tasks and reducing boilerplate code. The current version is 0.5.4, released on January 15, 2021. The library has a slow release cadence, with no new versions in over three years, suggesting it is in maintenance mode rather than active development.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `imutils.resize` to scale an image while preserving its aspect ratio. It first creates a dummy image (you'd typically load one with `cv2.imread`) and then resizes it to a specified width. Both the original and resized images are displayed using OpenCV's `imshow` function.

import cv2
import imutils
import numpy as np

# Simulate reading an image (replace with cv2.imread('path/to/image.jpg'))
# For demonstration, create a dummy black image (BGR format)
image = np.zeros((300, 500, 3), dtype="uint8")
cv2.putText(image, "Original Image", (100, 150), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)

# Use imutils.resize to resize the image while maintaining aspect ratio
resized_image = imutils.resize(image, width=150)

# Display original and resized images
cv2.imshow("Original", image)
cv2.imshow("Resized (width=150)", resized_image)

cv2.waitKey(0)
cv2.destroyAllWindows()

view raw JSON →