Artificial Intelligence 10 min read

Popular Python Libraries for Image Processing with Installation Commands and Code Samples

This article introduces ten widely used Python image‑processing libraries—including Pillow, OpenCV, scikit‑image, imageio, mahotas, SimpleITK, imgaug, face_recognition, Pyradiomics, and tqdm—provides brief descriptions, pip installation commands, and runnable code examples to help developers choose the right tool for their computer‑vision tasks.

Test Development Learning Exchange
Test Development Learning Exchange
Test Development Learning Exchange
Popular Python Libraries for Image Processing with Installation Commands and Code Samples

Image Processing Libraries Overview – The following Python packages offer diverse capabilities for image manipulation, computer vision, medical imaging, and data augmentation.

1. Pillow – An actively maintained fork of the Python Imaging Library (PIL) that supports many file formats and provides powerful image‑processing functions.

Installation:

pip install pillow

Example:

from PIL import Image
# Open an image
img = Image.open('image.jpg')
# Resize the image
resized_img = img.resize((300, 300))
# Rotate the image
rotated_img = img.rotate(90)
# Save the result
resized_img.save('resized_image.jpg')

2. OpenCV – An open‑source computer‑vision library for real‑time image processing, widely used for object and face detection.

Installation:

pip install opencv-python

Example:

import cv2
# Read an image
img = cv2.imread('image.jpg')
# Convert to grayscale
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Load Haar cascade for face detection
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
faces = face_cascade.detectMultiScale(gray_img, scaleFactor=1.1, minNeighbors=5)
# Draw rectangles around detected faces
for (x, y, w, h) in faces:
    cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)
# Display the result
cv2.imshow('Image with Faces', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

3. scikit-image – A SciPy‑based image‑processing library offering a collection of algorithms and utilities.

Installation:

pip install scikit-image

Example:

from skimage import io, filters, feature
# Load image as grayscale
img = io.imread('image.jpg', as_gray=True)
# Apply Gaussian blur
blurred_img = filters.gaussian(img, sigma=1.0)
# Detect edges using Canny
edges = feature.canny(blurred_img, sigma=1.0)
# Visualize edges
import matplotlib.pyplot as plt
plt.imshow(edges, cmap='gray')
plt.show()

4. imageio – A simple library for reading and writing a wide range of image formats.

Installation:

pip install imageio

Example:

import imageio
# Read an image
img = imageio.imread('image.jpg')
# Save the image in another format
imageio.imwrite('output.jpg', img)

5. mahotas – Provides fast 2D/3D image‑processing algorithms such as filters and morphological operations.

Installation:

pip install mahotas

Example:

import mahotas as mh
from mahotas.features import surf
# Load image as grayscale
img = mh.imread('image.jpg', as_grey=True)
# Compute SURF features
features = surf.surf(img)
# Display the image
mh.imshow(img)

6. SimpleITK – A simplified interface to the Insight Segmentation and Registration Toolkit (ITK) focused on medical image analysis.

Installation:

pip install SimpleITK

Example:

import SimpleITK as sitk
# Read a DICOM image
img = sitk.ReadImage('image.dcm')
# Convert to NumPy array
img_array = sitk.GetArrayFromImage(img)
# Apply Gaussian smoothing
blurred_img = sitk.SmoothingRecursiveGaussian(img, sigma=1.0)
# Write the processed image
sitk.WriteImage(blurred_img, 'output.dcm')

7. imgaug – A library for image augmentation, especially useful in machine‑learning pipelines.

Installation:

pip install imgaug

Example:

import imgaug.augmenters as iaa
import imageio
# Load image
img = imageio.imread('image.jpg')
# Define augmentation pipeline
seq = iaa.Sequential([
    iaa.Fliplr(0.5),          # horizontal flip
    iaa.GaussianBlur(sigma=(0, 3.0)),
    iaa.Affine(rotate=(-45, 45))
])
# Apply augmentation
augmented_img = seq(image=img)
# Save result
imageio.imwrite('augmented_image.jpg', augmented_img)

8. face_recognition – A user‑friendly face‑recognition library built on dlib.

Installation:

pip install face_recognition

Example:

import face_recognition
import cv2
# Load image
img = face_recognition.load_image_file('image.jpg')
# Detect face locations
face_locations = face_recognition.face_locations(img)
# Draw rectangles around faces
for (top, right, bottom, left) in face_locations:
    cv2.rectangle(img, (left, top), (right, bottom), (0, 0, 255), 2)
# Show the result
cv2.imshow('Image with Faces', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

9. Pyradiomics – Extracts radiomics features for medical‑image analysis.

Installation:

pip install pyradiomics

Example:

import radiomics
from radiomics import featureextractor
# Initialize feature extractor
extractor = featureextractor.RadiomicsFeatureExtractor()
# Read image and mask (DICOM)
image = sitk.ReadImage('image.dcm')
mask = sitk.ReadImage('mask.dcm')
# Extract features
result = extractor.execute(image, mask)
# Print features
for key, value in result.items():
    print(f"{key}: {value}")

10. tqdm – A progress‑bar library useful when processing large batches of images.

Installation:

pip install tqdm

Example:

from tqdm import tqdm
import os
# List all jpg files in a directory
image_files = [f for f in os.listdir('images') if f.endswith('.jpg')]
# Process each image with a progress bar
for file in tqdm(image_files, desc="Processing images"):
    img = Image.open(os.path.join('images', file))
    # Perform image‑processing operations here
    img.save(os.path.join('processed_images', file))

Summary – Each library has distinct strengths: Pillow for basic tasks, OpenCV for real‑time vision, scikit‑image for algorithmic variety, imageio for format handling, mahotas and SimpleITK for specialized domains, imgaug for augmentation, face_recognition for facial analysis, Pyradiomics for radiomics, and tqdm for progress monitoring.

machine learningcomputer visionPythonimage processingopencvpillowscikit-image
Test Development Learning Exchange
Written by

Test Development Learning Exchange

Test Development Learning Exchange

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.